How do I link Global variables with

Hellu everyone! I’ve been racking my brain out on how to do this and maybe you all can help me!

So, I have an object variable which is “Growth” it grows plants at a certain number in a scene. - I want a GLOBAL variable that counts days and I can link the passing of days. I have no idea how to do this. I fiddled around, I looked up stuff. I know what I want and I know what “needs to be done” but I have no idea how to execute this.

Also, the global variable I did make, counts weird.

The TL;DR - I want a global variable to count days and be able to link scene and object variables to it so it all works together.

I hope I made sense explaining, I’m not very good at that.
Thank you! :smiley:

1 Like

Maybe you could try using second object variable VegetablePlantDate and set it to current global variable CurrentDay variable only once when the vegetable is being planted. Then you could create third object variable DaysToMaturity which you could set for each vegetable type manually.

Then you could create an event to calculate your objects variables Growth like this:
object variable Growth = global variable CurrentDay - object variable VegetablePlantDate

Then you could create a check:
if object variable Growth >= object variable DaysToMaturity
then plant has matured

Basically, you need to create more object variables to track more data.

1 Like

You’ve done it correctly by the looks of things, the only issue is that you aren’t setting the days text in each scene when it starts up or resumes.

Add an event in each scene with a “At the beginning of the scene” condition, and an action that sets the text object “Days_global_text” (as you already do in the bed click event). That will see the number appearing when the scene starts.

However, if you are pausing one scene to start the second and then resuming the first scene from the second, then modify the events you just added so the conditions are “At the beginning of the scene” OR “The scene has just resumed”.

1 Like

oh my goodness bless you! I was gonna need that to work properly for when I set up seasons and stuff. It works now! Thanks! :smiley:

Alright that all makes sense but where do I put those conditions?
This is how I have it now, before adding those in. Do I put all that where “e key press” is, or someplace else?

And do I put “DaysOfMaturity” instead of a number where “Growth of Plants = 2” or do I use both?

I’m not trying to be difficult, I’m just still learning the variables stuffs.
Thanks!

do you mean the “Growth in 10 days” condition?
that depends on your game logic and how you manage days in your game, but a bulletproof way would be removing any preconditions for “Growth in 10 days” section, so that they will be making checks “all the time”. think of it as a part that only watches how much the plants have grown.

the second task would be setting this object variable Growth value.
you can use the action i wrote above

object variable Growth = global variable CurrentDay - object variable VegetablePlantDate

for now it doesn’t need any conditions.

you can now monitor changes in growth and set growth for every plant automatically.

And do I put “DaysOfMaturity” instead of a number where “Growth of Plants = 2” or do I use both?

If you want to implement this like on your screenshot above, then this object variable is not really needed anymore because your plant has matured(bloomed) when the object growth value = 10.

if you still would like to use this variable, then you could use this like this:

the variable growth of Plants ⩾ Plants.Variable(DaysToMaturity) -> change the animation of Plants set to "bloom"

My advice for you is to take complex mechanics, break them into smaller and simpler task and then implement them one by one. That should help you find what’s need to be done to achieve your main goal.

1 Like

I’ll try and figure out how to do this soon. Thank you!

I’m trying to figure out where to put these variables and it doesn’t let me do ObjectVariable and I’m confused. What am I doing wrong? :frowning:

To reference an object variable, use the dot notation - < object >.< variable>

So in your case, “Plants.DaysToMaturity

1 Like

ohhh okay, thank you!

SO - Its been a couple months and I thought I had it working, which I did kinda with it talking to the other scene for going to sleep and I remember having sprites work, but either I dreamed that or I broke it, either way they do not. :expressionless:

This is how I’ve gotten it to work:

But here is my problem, lets say I plant a seed, and 3 days pass - the sprite has changed once, if I plant another seed, the sprite changes to the others and doesn’t remain the seed sprite. Also once a full growth cycle has happened its just permanently planting full grown seeds.

I feel like its taking the Days = (X) and once the days = the number for the sprite to change in the structure to be the bloomed sprite that’s it. I don’t know any other way to get this to work, I’ve tried for days.

I’ve gotten it to work within the garden, but once it comes to linking that to another scene it doesn’t work. This is the only way I’ve gotten to work between scenes.

Video showing what its been doing:

Any help would be appreciated, thank you :3

Yes, because you’re not taking into account the number of days already elapsed when a new plant is created.


So, say for example you have:
1_sprout = 1 day,
2_seedling = 2 days,
3_bud = 3 days and
4_bloom = 4 days.

Now say the global variable Days is 3. When you create a new plant the first 3 conditions are automatically met by the new plant. So it jumps automatically to bud.

What you should do when you create a new plant is set the plant’s variables to take the global variable Days into account, like:
1_sprout = GlobalVariable(Days) + 1
2_seedling = GlobalVariable(Days) + 2,
3_bud = GlobalVariable(Days) + 3 and
4_bloom = GlobalVariable(Days) + 4

This will factor in whatever day the plant was created.

1 Like

Okay, that makes sense. Do I put it when I spawn a seed/plant or some place else? I tried a few places.

I tried to put it in my spawn toggle as a test and it still spawns whatever the days are.
attempt3

Then I tried to also have it start as a seed sprite and it just was that sprite and wouldn’t change.

I also tried to add to the part that already worked, and it didn’t change anything.

And I tried to have it by itself, and nothing happened.

attempt2

I got the concept but apparently I’m not putting it in the right spot.
I’m still learning how variables work so I have lots of blonde moments :expressionless:
Thanks!

When you create/spawn the new plant.


You need to modify all 4 of the variables, not just 0_base_seed.


No need to alter those conditions, they are fine.

1 Like

OHHHH All at once okay. It works now, this has been making me go mad for a long time. Thank you so much! :smiley: