Converting global variable into seperate variable

N

Nindota

Guest
I'm trying to convert the global variable global.points into a new seperate variable so I can do something like

global.points = tt
if tt > ff
{
global.points becomes ff
}

in this case ff would be the previous global.points saved as a new variable.
I have no idea if something like that would even work so please let me know if there is a way to do so.
 
N

Nindota

Guest
In doing that, it would be completely usless as when the global.points variable is to change it would change all other variables associated with it, therefor not converting the glabal.points code into a new variable but rather a variable built upon the global.points variable.

What I'm basically looking for is a way to extract the number from the global.score variable, create a new variable with that number inserted into it, and have it change to the global.points variable once it reaches a number larger than the variable created from the previous lower global.points value. I'm more or less trying to create a high score system so that the highscore will not be replaced with a number lower than the highest achieved score.
 
J

JFitch

Guest
Code:
highscore=max(highscore,global.points)
Something like that?
 
N

Nindota

Guest
I'll try it but I'm a bit doubtful if it will work or not.

Code:
highscore=max(highscore,global.points)
Something like that?
just crashes the game.
 
Last edited by a moderator:

obscene

Member
This is a crash:



If you get an error, you could let your game continue running if you chose.

If you posted that error instead of just saying crash, someone could also help you fix it. :)
 
N

Nindota

Guest
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object highscore_text:

global variable <unknown built-in variable>(-1610512735, -2147483648) not set before reading it.
at gml_Object_highscore_text_CreateEvent_1 (line 1) - highscore = max(highscore,global.score);
############################################################################################
 

obscene

Member
This error is telling you there is no such thing as global.score. If you meant to refer to the built-in variable score, it's simply "score" with no "global." before it.
 
N

Nindota

Guest
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object highscore_text:

global variable <unknown built-in variable>(-1610512735, -2147483648) not set before reading it.
at gml_Object_highscore_text_CreateEvent_1 (line 2) - highscore = max(highscore,global.score);
############################################################################################
 
N

Nindota

Guest
I wrote the code wrong, I keep doing that, I keep writing points instead of score which is what I'm supposed to be writing.

Now this

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object highscore_text:

Variable highscore_text.highscore(100027, -2147483648) not set before reading it.
at gml_Object_highscore_text_CreateEvent_1 (line 2) - highscore = max(highscore,global.score);
############################################################################################

with the code being this

global.score = 0;
highscore = max(highscore,global.score);
 
Last edited by a moderator:
N

Nindota

Guest
Set highscore to start out as = 0, doesn't do anything, gets set back to 0 when global.score goes back to 0.

same goes for any other number.
 
Last edited by a moderator:

obscene

Member
Make sure you don't run that code again (highscore=0).

Not knowing exactly how you have set your project up it's hard to say exactly what is best... but here's the idea.

Have a controller object in your game that is created when your game starts and is persistent. This object will create all of your global variables. You should probably make highscore a global variable as well. Whatever is in the create event of this object will only run one time, so it's a great place to set all those values to 0 one time, knowing it won't be repeated.

At whatever point in your game you want to set the highscore... simply say...
global.highscore=max(score,global.highscore);
and then set your score back to 0.
 
N

Nindota

Guest
Even when a global variable is put into a create event it will act like a step event.

Here's a potential sequence of events for what I'm trying to do, please try your best to follow it.
global.score = 11, tt does = 11 but not glabal.score, global.score changes to 12, now tt = 12 but not global.score, global.score now changes to 8, tt = 12 not 8 or global.score, global.score then changes to 13, tt = 13 but not global.score.
 
Last edited by a moderator:

obscene

Member
Even when a global variable is put into a create event it will act like a step event.
Sorry but what you are saying is not possible, you are misunderstanding something. A create even only runs one time, when the object is created. If you don't create the object again, the code will not run.
 
N

Nindota

Guest
Sorry but what you are saying is not possible, you are misunderstanding something. A create even only runs one time, when the object is created. If you don't create the object again, the code will not run.
I put a global variable into a create event for an object, as the global variable changed, so did the object with the create event, all that was in the object was the create event with one line of code.
 

obscene

Member
Do you understand that global variables are "global?" Meaning that there is one variable, in the entire game, shared by all objects? If you had 1 billion objects all check the value of a global variable, they will all return the same value. This is what a global variable is for.
 
N

Nindota

Guest
Do you understand that global variables are "global?" Meaning that there is one variable, in the entire game, shared by all objects? If you had 1 billion objects all check the value of a global variable, they will all return the same value. This is what a global variable is for.
I know that, but when I used a global variable in a create event, when the global variable was changed through another object, the global variable also affected the object with the create event acting as though it were a step event.

So, this?
Code:
tt = global.score;
if tt > ff
{
  global.points = ff;
}
Not quite, doing this won't actually do anything at all.
 
Last edited by a moderator:

obscene

Member
I know that, but when I used a global variable in a create event, when the global variable was changed through another object, the global variable also affected the object with the create event acting as though it were a step event.
Sorry, but again, what you say makes zero sense. Maybe explain exactly what is happening. If you define a variable in create event, that value does not change unless you (A) change it or (B) there is no B.
 
N

Nindota

Guest
There's no point in explaining it as this is going completely off topic.
 
Top