GMS 2.3+ Help Loading/Saving Variables (DnD)

id07

Member
Need someone to please explain what this means:


Variable obj_follower_counter.follower_count(100005, -2147483648) not set before reading it.
at gml_Object_obj_follower_counter_Step_0 (line 6) - if(follower_count <= 0)
############################################################################################
gml_Object_obj_follower_counter_Step_0 (line 6)


I've made a simple counter program (click a button and numbers go up or down) - entirely using DnD.
Game starts and ends perfectly.

But I wanted to save the counter/numbers on "ending the game"

So, I created an object called "obj_checkpoint" and inside I created two events

event->gamestart-> loadgame
event->gameend->savegame

I have just one room with the number counter objects, that the "checkpoint" also exist in...all objects are in the same room.

Well, when I open it for the first time, it works, but when I open it again to test, I get the error.
Removing the "obj_checkpoint" allows me to open it, but of course without the save function.

I previously did this in GM1.4 and it worked, but I tried to recreate it in GM2 and Ive got errors.

Any help is appreciated!
 

Nidoking

Member
This refers to a variable, a name attached to storage of a single piece of information.

obj_follower_counter.follower_count
This tells you that the name of the variable is follower_count, and that it's referenced in an object called obj_follower_counter. The dot makes the variable part of an instance of that object.

not set before reading it.
This means that you tried to get the value of the variable without actually putting a value in the variable. You can't read an empty book.

at gml_Object_obj_follower_counter_Step_0 (line 6)
This says that the problem is on line 6 of the Step event for the object obj_follower_counter.

if(follower_count <= 0)
This shows you the actual line, just in case you can't count. Here, it's using the follower_count variable by comparing it to zero. The runtime engine says that you never gave follower_count a value, so what is it supposed to do? What it does is crash.

Since you haven't described the obj_follower_counter or the follower_count variable in your post, no more information like that could possibly be provided by anyone, but I hope you've found this lesson in reading illuminating and can take more steps toward solving your problems in the future.
 

id07

Member
Thank you for the reply and break down.

I want the variable to be at zero at the start of the initial program. It is literally a counter that keeps track of individual digits. I push the button and it counts upward. The obj_follower_counter and the follower_count are two separate/individual counters, they both start at zero and when I click the object, which has a transparent sprite over it, it just counts up. So if the case is that I have to assign a "value", I guess I'll assign the counters to have he value of "1" initially?

I don't understand why it works without the save function. Because it works fine, but when I add the "obj_checkpoint" it crashes.
 

Nidoking

Member
I don't understand why it works without the save function. Because it works fine, but when I add the "obj_checkpoint" it crashes.
Then you're doing something wrong with the obj_checkpoint. I don't know what you're doing wrong, because I don't know what you're doing. You've posted zero bits of code (or DND) for anyone to evaluate. But it would stand to reason that it's creating an obj_follower_counter and not initializing the follower_count. Again, the error message explains all of this.

However, this
The obj_follower_counter and the follower_count are two separate/individual counters
makes no sense at all. One is an object and the other is a number. Or is follower_count not a variable of obj_follower_counter?
 

id07

Member
Here's what it is (images attached).

Four objects with their own variables each

obj_follower_counter
obj_follower_current_counter
obj_sub_counter
obj_sub_current_counter

each object has it's own variable inside of it as a create event:

obj_follower_counter->create->"follower _count"
obj_follower_current_counter->create->"follower_current"
obj_sub_counter->create->"sub_count"
obj_sub_current_counter->create->"sub_count_current"

each object also has a step event:

if variable is less than or equal to zero, then set the variable to zero.

When you click on one of the four objects, the number goes up or down with left/right click and center/wheel click resets the individual counter.

Works fine as far as I can tell.

I would like it to save the variables when I exit the app, but when I include the "obj_checkpoint" into the same room of the 4 different objects I get the error.

I have the checkpoint objects as:
roomstart->load "follower_save.dat"
gameend->save "follower_save.dat"

Many thanks for your help!


img1.pngimg2.pngimg3.pngimg4.pngimg5.png
 
Last edited:

Nidoking

Member
The page for Save Game in the Manual specifically says that it's not meant to be used to carry information from one execution of the game to another. Something weird is probably happening when you load the game.
 
Top