A thing-place

Month

January 2010

2 posts

Jan 18, 2010
Debugging!

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

draw_text(100,100,”YES”)

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[0].text (which the debugger assures me is stillĀ ”foowoiwefjg”) - still nothing. I try it with runs[0].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.

Jan 12, 2010
Next page →
2011 2012
  • January 1
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
2010 2011 2012
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December 1
2009 2010 2011
  • January 2
  • February
  • March 1
  • April
  • May 1
  • June
  • July
  • August
  • September
  • October 2
  • November
  • December 1
2008 2009 2010
  • January
  • February
  • March 3
  • April 1
  • May 2
  • June
  • July 1
  • August
  • September
  • October 1
  • November 3
  • December
2007 2008 2009
  • January
  • February
  • March
  • April 1
  • May
  • June
  • July 2
  • August
  • September
  • October
  • November
  • December
2007 2008
  • January
  • February
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October 2
  • November 1
  • December 1