Boolean Variable not loading from structure variable in storage [Solved]

How do I…

Hello! I am currently working on a game where you hire units. Whether or not a unit is hired is determined by a boolean called “Hire” within the object structure variable “Instance”.
Hire = True - Object is hired and performs its actions
Hire = False - Object is transparent and gray

I had already written a save system following some tutorials and forum posts but then I discovered this post:

and found there was a simpler way to save the instance variables of my objects without typing out an individual line for each variable I wanted to save. The previous method was correctly saving and loading the boolean but the new method refuses to work. I thought I found the answer when I saw I forgot to update the boolean to “Instance.Hire” in the other places it was used in the events sheet, but nope. Still doesn’t work. When I open the game

Im not sure whats wrong. I just tried converting the scene variable “Load” that loads the object variable into a structure variable itself but that didnt do anything.

Related screenshots


Here’s my events and conditions. I mistakenly thought that I could skip having to write the save & load events for the X & Y positions of the objects but then remembered that I need to load parsed JSON onto the object(that is why Instance.X & Y are modified and saved).

But thats not why boolean isn’t loading.

Thank you all in advance for your help. This is my first post but this forum has already helped me solve many problems before this one.

I don’t see the “save” events. Could you post them? The problem might be there.

Here’s another way of saving objects x,y and a variable named “qwerty”
Instead of saving the variables separately, it creates a temp structure, adds it to an array and saves the entire array. To load, it loads the text into an array and uses the for each child

I’ll have to try that thank you. Also I inserted the screenshot for the save events after the load screenshot. Thanks for pointing it out to me!

1 Like

It’s a lot of events and I’m not in the right frame of mind to do a deep dive bc I’m not sure about the concept. The save and load looks good. Again, not fully understanding the concept, does the effect need to be disabled after the object is created and/or set depending on the value of the Boolean. Or maybe the state of the effect needs to also be saved. IDK, I’m just brainstorming.

This I’m not sure of

I’m wondering if it should be
check distance
check hired Boolean
variable cost of pollinators < variable Seeds
pick a random pollinator

If you check cost against the object, i believe it will be true as long as the first created instance in the group is true. I don’t think it will check the other objects. It also doesn’t change the pick status of the objects. The comparison behaves differently depending on the order of the values being compared.

On the other hand, if you compare the object to the scene variable it will only pick the ones below the scene variable. It’s up to you whether this should be < or <=

I moved the pick to last because otherwise it might pick the closest but if the closest doesn’t have the right value then it wouldn’t pick anything. It’s better to filter out the invalid objects first.

Yeah, it could definitely use a bit more optimizing. The effect “Ghost” (which makes them transparent and gray) is enabled depending on the value of boolean. By default the boolean is false, which enables the effect. The effect “Select” lets you know which object is currently selected by the events, and is used by the event at the top of the hire events sheet. Thanks for the suggestions.
I wonder if turning it to a number variable would work at all? Maybe that would work.
I still need to try out the save/load events you shared with me. Do I still need to include the UID counter? I pulled it from the “Level editor” example.

Also, temp is a structure that is loaded into the array, right?

My example doesn’t need a counter. So, no uid unless you need it somewhere else. Yes, temp is a structure that gets added to an array. The nice thing is you can add any value to the structure as long as it’s in the load and save. Things like size or animation.

You can also use it with multiple objects. Save the object name and in the load section use create object by name and use

I love Boolean variables. Variable names like isPicked is true or isGhost is true makes it easy for me to read.

1 Like

Cool. I’ve started implementing it though and I’ve run into some problems. They don’t seem to want to load. Do you see any problems in my code? Currently I’m gonna try and see if I can reproduce in a separate project to see if I can get it work on its own. Thanks for all your help.



Ok, I kind of figured it out.

I tried what they showed in this forum post with “Create “Shape” + ToString(Variable(child.Name))” and it works for some reason. Only catch is they all have to begin with the same word, and end with a number. For some reason I cant do “Shape” + “Square” or “Shape” + “Circle”. I think I’m ready to call this solved, I just wonder if this is a bug or something. Why cant it do “String” + ToString(Variable) unless the ToString is a number?
Any way, thanks so much for your help. You’ve saved me a lot of unnecessary typing. Have a nice day!

Edit: before posting this comment I realized I had mistakenly used ToString for variables that were already strings. After changing them to VariableString it now works perfectly. facepalm Again, thank you so much.

1 Like

Your welcome. Good to hear.

Instead of using the object variable instance.Name for the object name, you can use: set to groupName.ObjectName()

1 Like