Watering some trees, the right trees. Instances.

Around the time of the previous post, I had no idea how I was going to allow for the creation of objects that share the same code, but not inherit each others ‘events/history’ from the moment of creation onwards allowing them to be unique. I suppose this is due to the fact that i’m a beginner with this whole thing but I have since figured out how to get things working perfectly in regards to this one problem.


So previously when i wanted something to happen to an object, I was ‘calling’ it by its object name rather than the instance ID. This was a problem due to me not being able tell the game which exact tree I wanted something to happen to as they all share the same object name and code.

Then I found instances so I was able to draw each objects unique instance next to it and see if I could then call on that number rather than just the object. It would be much easier if these objects were static and never changed locations in the world but if they are grown by the player, then that introduces a whole lot of randomness in terms of where it will be placed etc. Also, the main problem I was having was due to getting in a habit of using global variables instead of local ‘disposable’ ones. I’ve learned to be a bit better at that now.


So even though these two are identical in terms of their code,sprite and object name, they both have a unique identifier to differentiate one from the other.

if you can ignore the temporary sprites which are just there to show growth over time, you can see below a very basic starting point for a system I’ve been working on where I wanted the player to be able to plant their own trees anywhere. I’ll improve this somewhat like I did with the first inventory system once I get the basics implemented.

Once those trees are grown they will have their own activity log unique to each one (unique to each of the object’s unique instance ID) showing world events impacting it. Also birds will randomly choose one as a home based on a number of factors as well as tons of other cool stuff.

Below, the growth process is sped up just to show the typical stages and the need to water them. The numbers can be ignored, they are there so that I can tell if things are working as they should. Can everyone also take a moment to look at the state of that watering can…


I had a bit of a problem with the water effect hitting the right plot of land due to the fact i’m not totally comfortable with particle systems. This watering can and rain are the only two times I’ve tried creating with particle systems.  Weirdly, the stuff i’d learned about instances and instance_nearest(x,y,objects) with the trees helped with getting the particle emitter to shoot water over the right area at the right time. I read other ways to do the same thing but it seemed way over my head for now so I just stuck to using what I knew. I can always improve it further down the line.

Wet soil

I’ve added dry soil which requires water in order to further the growth of a tree. This can be solved by either the weather being rainy, or a watering can / a similar tool.

When the soil receives  water it changes colour as you’d expect and also allows the plant / tree to progress in regards to growing. This can be seen in the below examples:


Comparing tree growth in watered soil to none-watered :


Rain obviously impacts the soil and trees the same way a watering can would but consistantly


I feel like the way I’ve made this work is a bit bodged. As I learn more about GM’s coding, i’ll try and improve it. I’ll need to have a look through it properly once i’ve slept and make sure nothing weird is happening.

Hopefully next blog will be more interesting. Just taken me a while to get this working as i’m still learning.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s