Regeneration and randomness

A big part of this game is randomness , which is obvious, since it is based on random generated terrain. I have my work cut out for me on that part, as I am going to have to eventually get the terrain generator to pick from terrain types in order to get it to get real interesting.

For now, I want to focus on placing apples in trees, berries in bushes, and regrowing trees ( and burning trees ) .

Right now, trees are being placed in the aux tile map. I think this should be the focus of where this action is happening. The aux tile map script really only holds its perlin noise info, and doesn’t do anything else – the main terrain generator script is responsible for creating that map, so the aux tile map script can be used for regeneration and random placement of things ( fruit, sticks, stones etc,… )

The first part of this should be regenerating trees after they are cut down. So within the aux tile map script, we will first have to create an array of tiles that are now cut down, that we will need to set a timer for and check when they can be regenerated.

WHich is all fine and dandy, but now I am getting a null reference when trying to check the tile and so forth. What is odd, is that it is throwing the exception because there is no tile there, according to the reference, hence the throw.

The process starts in the map generator by way of the player script after harvesting ( makes sense ? ). It calls into the map generator which has the aux tilemap itself , and that calls seems to be coming up blank. I checked the whole script and can’t seem to find the reason why the data would be gone or missing.

After a couple more days, I have concluded that I somehow forgot ( lol, i know, right? ) that there was no “nothing” tile, which is apparently something I had programmed in before, with the intention of doing, but never did.

Still not positive why the null reference, but when simply placing a different sprite on the tilemap, it drew underneath the trees, and in a different spot ( one square to the right ). So its possible it was grabbing a blank tile and then throwing the exception because there was in fact, nothing.

SO! A couple days later and I got it figured out. Even though the aux_tilemap had a Zed of -1 ( to show above the base tile map ), the tiles were placed on the 0 Zed of the aux tilemap . So when I was grabbing the tiles, I checked the editor for the zed of the map , and I did not check the script for which zed the tiles were being placed. The nullreference was being thrown because there was no tile there, hence why the mountains tile was being placed below the trees.

So now it works. Player harvests, the tile is replaced with a stump tile, time goes by, and it grows back. Freaking awesome!

Leave a Reply

Your email address will not be published. Required fields are marked *