Suggestions (Project One)

Persistent Problems

Using other peoples’ code

This is great! Do this more! BUT in so doing, try to take greater advantage of what they are giving you. In many cases, for example, the tutorials from which you’re borrowing are probably making things more difficult, not less: They fill up your program with lots (and lots!) of unrelated stuff, and make use of techniques that don’t quite square with ours, etc.

Again: That’s not bad — in fact, that is the single best way to learn, in my mind. However, plugging the code in and crossing your fingers is just the first step to making use of it. What you want to be able to do eventually is force the code to reveal its secrets to you — in other words, you want to keep changing things slowly over time so that you can better understand how it works, and maybe even why the developers chose to use that approach. This is a laborious and slow process at first, but you’ll get better at it as you become more familiar with more programming techniques.

Remember this, though: Your goal is always to be able to “run” your code in your head. You should be able to work through your code just like the computer will (howbeit in a slightly slower fashion). That means that you should (eventually) be able to explain what every single line of code does. (Hint: As you figure them out, add a comment or two to keep track of what is going on).

Here’s another approach to consider (and again, these are great exercises to create for yourself and work through every day). I call this UNPACKING.

Here’s some code taken directly from a tutorial on creating scrolling marquee text. I can make use of this for a project I’m working on — but I want to make time to insist that I understand how it works. We can do this by taking the code apart and breaking it down as far as we can.


Original marquee tutorial code

CREATE EVENT

my_string = "Some text for your marquee "
start_letter = 0;
marquee_length = 10; // or however many letters in your marquee
type_rate = 3/room_speed; // 3 char per second
marquee_scrolling = true;
DRAW EVENT
if marquee_scrolling{
draw_text(x, y, string_copy(my_string, start_letter, ceil(start_letter + marquee_length)));
start_letter += type_rate;
if (start_letter > string_length(my_string)) start_letter = 0;
}

With changes:

CREATE EVENT
// Text to draw to marquee on screen.
my_string = "Some text for your marquee ";
// Always (usually) count from ZERO! start_letter is a pointer
// that tells us where the marquee should begin grabbing text from
start_letter = 0;
// So this is weird. 10 characters is not the length of my marquee.
// Why doesn't this line up?
marquee_length = 10; // or however many letters in your marquee
type_rate = 3/room_speed; // 3 char per second
marquee_scrolling = true;
DRAW EVENT
if (marquee_scrolling == true) {
// how many letters total are we getting?
var totalCharacterQty = start_letter + marquee_length;
// get the ceil of that number means just "round up" in case decimal point
totalCharacterQty = ceil(totalCharacterQty);
// get a chunk of text as a string, starting with start_letter
// and running through totalCharacterQty's letter
var textChunk = string_copy(my_string, start_letter, totalCharacterQty);
 // now draw that chunk
draw_text(x, y, textChunk);
// move forward in string start based on our speed
start_letter = start_letter + type_rate;
// how big is the marquee now (why are we always recalcing this?)
var totalMarqueeLetterQty = string_length(my_string);
// Are we past the last letter?
if (start_letter > totalMarqueeLetterQty) {
// have we gotten to the end of the marquee?
// start over with the zero-position character!
start_letter = 0;
}
}

Coditionals

If() {

// code block
}

Repetition

Repeat() {

// code block
}

For() {

// code block
}

Leave a Reply

Your email address will not be published. Required fields are marked *