Can anyone see why this integer will not count?

Hi Guys,

So, I’m not just relatively new to game development and coding and such, I’m fresh as a daisy. I’ve done a small course on udemy and some tutorials and I feel as though I’m slowly getting there. However! I seem to have come against a problem with what I feel is a simple piece of logic but for some reason wont work!

I ran through the tutorial to create an endless runner, and have decided to build on it as an aid to my learning.

I have a construction script that continuously spawns a selection of three different tiles, a tile with blocker, a tile with pickups and a tile with a speed boost. The problem arose when I decided to limit the spawn rate of the boost tile. I thought I’d add a simple counter at the end of each spawn of the other two tiles, which would eventually change a boolean variable from false to true. I had written the logic for it which seemed fine but for some reason my tile count integer doesn’t increment. See the screen shot below.

I’ve removed all the logic that I wrote just to see if a simple count worked… which it didn’t. Is there something obviously wrong here? All I’m asking it to do there is count 1 every time it spawns a boost tile and print the variable to the screen, but all it does is print a 3 every time the tile spawns. I know there’s an increment integer node now, and I got the same result when using it.

I hope this is a good enough explanation of my issue, like I said… Im a total n00b here.

Any help is appreciated,

Thank you in advance.

You are creating this in the construction script which only runs once each time you change the blueprint. So move it, scale it, edit something within the editor/event graph/construction script etc. Basically that variable is always 3 because the default value must be 2 and each time the construction script runs it adds 1 and you get 3. It will never “increment” the way you expect because that variable is read from default (2) each time the construction script is run. If you want it to actually increment you need that entire chunk of code in the event graph not the construction script.

This is brilliant, thank you very much. I now have this working. Once you’d explained it, I could see exactly what was happening. Instead of moving the whole script, I created the variables in the game mode blueprint and called on them from there. Works an absolute treat. Thank you again for you answer :slight_smile:

This is now what the full script looks like - An abomination :wink: :