Jump to content


BBGaming

Member Since 11 Jun 2006
Offline Last Active Private

Posts I've Made

In Topic: Global Variables Not Working

21 May 2013 - 12:23 AM

A normal practice is to make a 'loading room' whose only function is to initialize the game: setting variables, loading resources, calling libraries, etc. If it's global variables you need to set, do it in this loading room and then immidiately go to the first actual room of your game.

 

If it's local variables you're talking about, you're going to have to be more specific because I'm not following you completely. For a local variable you always have to initialize it in that object before you use it, usually in the create event. What situation do you have that you can't initialize in the create event for the object?


In Topic: Collisioning

19 May 2013 - 04:02 PM

I know how to make great horizontal collision code. I just feel like you'd learn more if you let us see your code as of right now, and let us help you fix that.

 

But, if you're pressed for time, here's how I do platform collisions. Here's a more in-depth example on platform collisions.


In Topic: Alarm Problem Solved

19 May 2013 - 03:41 PM

In Game Maker, the alarm[] variables automatically count down by one each step, you shouldn't need to do it yourself. What you're probably doing is doubling up and making your alarm last only half the desired time.


In Topic: Objects And Surfaces

19 May 2013 - 03:39 PM

As an aside, you also have to do this for data structures and code-created resources (like sprites and backgrounds). Game Maker stores these globally but usually the reference to them is only stored locally so by deleting the object you lose your ability to reference them but they still reside in memory. This is so you can save the reference id in a global variable and allow all the objects to access it, or transfer it between rooms, if the need arises.


In Topic: Global Variables Not Working

19 May 2013 - 03:34 PM

Just to clarify a little further, the reason you're getting an unknown variable error is because with variables you create yourself, Game Maker doesn't know what they are until you specifically tell it. So when you run the code you have now, the global.hsp variable doesn't actually exist until you press the right key and the walk_box event happens. Before that happens you're asking it to draw a variable which you haven't given a value yet. It'd be like if I ask you to tell me what channel my TV is on; there's no way for you to know unless I tell you first.

 

To fix that problem, you have to tell Game Maker what the variable is before you use it. It's called 'initializing' the variable, and usually you just set it to zero to signify 'no value.' Do this in the create event somewhere.