ForumsProgramming ForumHow to set a global variable?

3 2935
Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Hey guys, long time no see

My game is almost ready, but I'm having a problem with global variables, not as simple as just setting them as the title sugests

So, here are some ways the global variables do work

_global.mywar = "yay";
_global.mywar = 10;
_global.mywar = _global.mywar + 10;

No problem there, however, if I have a var, called "score" which keeps track of player points, and have a "totalpoints" var, which keep these points as a form of in-game credit, but I can't do this:

if(at the end of the level)
{
_global.totalpoints = _global.totalpoints + score;
}

It doesn't work. So how am I suposed to add the numeric value of the "score" var to my global variable?

  • 3 Replies
Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Ok, bizarre update, the global was working, my debug text wasn't

mydebug.text = _global.totalpoints;

This is what is not working, for some reason it only works when showing 0

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Well, thanks for the atention, but I managed to solve it

For some reason the text didn't want to work with just Dynamic Text, so I put it inside a Symboland it worked

If someone knows why this happened, I'm interested

PixelSmash
offline
PixelSmash
566 posts
Nomad

What'll be really nice is if you try to migrate that to AS3... the whole _global has been ripped out, without a real replacement ^^;

Showing 1-3 of 3