• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Setting a global variable

A

AutoLiMax

Guest
Hi, I'm probably making the most noobish mistake but I need some assistance.

I'm basically trying to create a global variable named "equipped" and then make that variable hold a string such as "shovel" or "fists"

This runs when "1" is pressed.
Code:
globalvar equipped;
equipped = fists;
When I press "1" the game returns an error saying it hasn't been set before reading it.

Now what am I doing wring?

Thanks!
 
B

Becon

Guest
global.equipped is a global variable named equipped. Call it the same way.
 
A

AutoLiMax

Guest
Hi thanks for the response. How do you mean call it the same way?
would you be able to provided me with an example?

Thanks
 
A

AutoLiMax

Guest
Even if i set:
Code:
var global.equipped = fists;
I throws the same error.
 
A

AutoLiMax

Guest
I think I've found out the issue. When setting the string I missed out the " " either side of the string.

Key work being I think. It'll probably be a disaster....
 
J

jackhigh24

Guest
when you use global. you dont also make it a var so just global.equipped = fists; you also dont need to pre set it like you did with globalvar = equipped just do the global.equipped = fists;
 
A

AutoLiMax

Guest
Chill your boots captain. I read through that before I posted. I had tried so many different combinations of getting it to work and even trying things that weren't likely to work. As I said previously the reason was because I had forgot the " " around the string.

global.equipped = fists; is how I originally attempted it.That did not work. I read the documentation and ended up trying literally every different method, watching youtube videos and such and ended up with a mess because I couldn't figure it out.

As I said previously further up the thread I missed the " ".
global.equipped = "fists"; is what I've done.

Also don't be such a condescending little turd. I'm trying to learn and people like you don't help.
 
A

Aura

Guest
For future reference, you'd perhaps want to post the complete error message; because it can be quite confusing to tell which variable you're using. As you have figured out yourself, strings need to be in the standard "string" format. You could have known that better if you had read the Manual entry on strings.

@FrostyCat was being helpful; their method of saying was a bit rude though, but that does not prove their point invalid. ^^

Also, since the issue's been solved, you'd want to set the status of the topic as solved. To do that, go to Edit Title/Thread Tools >> Edit Title >> Set the topic prefix to Solved.
 

TheouAegis

Member
If you actually read the error messages completely and not just the first two or three lines, you'd have seen that the error was fists was not defined before reading, then you would have noticed you missed the quote marks earlier and wouldn't have been confused at all.

GG has gotten grumpier over the years, but after 11 years of these forums, it's understandable.
 
Top