So I’m modding Spelunky, which is written in Game Maker.
Part of what I want to do involves drawing a bunch of previous scores to the screen.
I initially had my code just read them in from a file and spit them out onto the screen. This worked fine.
Next, I wanted to wrap the scores in objects, so that they could be manipulated in various ways. I went ahead and did it, changing the code in the for loop from something like
draw_text(20, 20 + (i * 20), file_text_read_string(file))
to something like
draw_text(20, 20 + (i * 20), runs[i].text)
Suddenly, no text appears. I’m not totally sure what’s wrong, but not that surprised, either, being quite unfamiliar with GML. So I go through the debugging motions, commenting things out and replacing them with constants one by one - first the file read operation gets replaced by “owiefj” or something, then the object creation call that took the result of that as a parameter, then the text-drawing itself: now I’m just calling
draw_text(20, 20 + (i * 20), “owiefj”)
and it’s still not working! Huh??
I glance at some working text-drawing code, and it looks identical. I comment out the whole Draw action and replace it with
I run it, and YES, there it is, right there in the middle of the screen. Could something be wrong with the for loop? No. Is the text somehow being drawn off the screen, or under something else? I fiddle for a bit, and no, the coordinates are all as expected and text gets drawn on top of objects. I but the above line inside the for loop, and (YES YES YES YES YES) there it is. I replace “YES” with runs[i].text — nothing. I run it in the debugger - what’s runs[i].text? “foowoiwefjg” or something, the constant I set it to when I was removing the file-read call. What could be wrong? Could it be something with variable interpolation?
I go to an unrelated place in working code that draws text and add
w = “iwjf”
draw_text(100, 100, w)
Nothing. Then I try
draw_text(100, 100, “iwjf”)
Still nothing! What!?? The exact same call is used the line previous in code I didn’t write, and it draws “SECRET CHALLENGES” to the screen just fine! Now I’m getting seriously worried.
I try Game Maker’s ridiculous graphical-programming method, dragging the ‘Draw Variable’ action over to the Draw event, and setting it to draw runs.text (which the debugger assures me is still ”foowoiwefjg”) - still nothing. I try it with runs.x instead, the built-in variable that gives an object’s x-coordinate. And there it is, a nice shiny 20 right where I told it to be. So it can only work with default variables? That makes no sense. I read through some documentation, and it has plenty of examples of printing out user-defined variables. I mean, obviously. I’m really scraping the bottom of the explanations barrel at this point.
I see an example of the Draw Variable action that adds captions - “Score: ” + string(score). Aha! So it can take arbitrary expressions. Okay, it could print out a variable whose value was a string, lets see if it can print a simple string. I open it up and, accidentally holding shift for some reason, type “OWIfiejk” into the input box.
I run it.
“OWI” is printed in nice, big, capital letters. “fiejk” is nowhere to be seen.
I die laughing.
Spelunky’s sprite font only defines numbers, a few symbols, and capital letters. And Game Maker doesn’t care if you try to print characters that don’t exist, so it didn’t raise an error. God damn.
The double extra punchline is that the values I was originally reading in from the file were all numeric - if I hadn’t carefully replaced everything with constants, everything would have been fine. I’m still not totally sure where the original bug was, but I think it’s that I wasn’t defining a variable in the proper GML way, something I fixed (to no visible effect) very early on in the above process.