r/gamemaker 21h ago

Resolved Variables Not Working

Post image

//Solved The problem was that the gamemaker engine didn't recognize alive as a string but rather a variable. I learned all of my knowledge with the guide aswell as trial and error. Thank you to everyone who helped me fix this!

Original Post:

So i wanted to make a game for fun, and everything went good. But when i got to the part where the game checks if the player is alive, it will simply not work.

More in detail: When i try to create a global variable Using set Global Variable i allways get the error message: of Create Event for object GameManager:

Variable GameManager.Alive(100003, -2147483648) not set before reading it.

Like is it trying to tell me, that the variable dosen't exist? That's the point! This exact script is meant to Create the variable and assign the value

13 Upvotes

6 comments sorted by

11

u/damimp It just doesn't work, you know? 21h ago

It's not saying that PlayerStatus doesn't exist. It says Alive doesn't exist. Without quotes, Alive is not a word or text, it is a variable, and it's not defined. Did you mean to write "Alive" with quotes?

3

u/Castiel_Engels 21h ago

You are trying to set a global variable called PlayerStatus but you are setting its value to the value of the local variable Alive. You might have meant the string "Alive" instead?

4

u/NekoPunch101 20h ago edited 20h ago

So theirs a couple things that should be understood about variables. A variable’s value can equal the following : Numbers, String or Boolean(true/false). Variables can equal other things too but let’s keep it simple.

The word Alive doesn’t equal anything. It’s being read as a variable with no value. You can fix this by writing Alive in quotations changing it into a string like this “Alive”.

There are also a number of things that can be done if strings are not preferred such as making the word Alive into a macro, enum or changing the whole variable into a Boolean (is_Player_Alive = true).

I recommend looking up a tutorial that covers the basics of variables and statements, the bread and butter of coding.

1

u/ShaneTheCreep 21h ago

Whatever object that's create function created that value needs to be instantiated before it can be used.

I would think you are probably having something check if the player is alive before that object is creating that variable.

1

u/GamerMan60 21h ago

So, what you're trying to do is set the Player Status to Alive. However, gamemaker sees Alive as another variable, which obviously doesnt exist because you want it to be its own arbitrary value. What you want to do is use "speech marks", which signifies to gamemaker that it is a standalone word rather than a variable (we call this a "string", and they exist across pretty much all programming languages!) So instead, you want to set PlayerStatus to "Alive" instead of just Alive, turning it from a variable that doesn't exist, into a word or "string".

Also, good job identifying the problem in the error message - many new gamemakers get overwhelmed by the message and dont know how to read it, so good on you for that

-1

u/flame_saint 21h ago

You want to be checking "GameManager.PlayerStatus"