variable not being changed outside of a method. [C#]

Hi, guys, hard to explain my issue in the title so I am glad you have clicked this :smiley:

Basically, I have a variable called housingNode that increases by 1 when a button is pressed, this works as tested with a debug.log but then in another method i have a variable called populationNode that is supposed to by housingNode multiplied by 5 yet it is always equal to 0 when called.

I hope these pictures help:

Imgur: The magic of the Internet This picture is of the Population class that is what I was referring to. I know the GainPopulation() works as It was successfully making populationNode equal to 1 * 5 but not equal to housingNode * 5, it always equaled 0.
Imgur: The magic of the Internet This picture isn’t really needed but it just shows where the GainPopulation method is being called every second, this works as I have tested it but it may help in resolving the issue.
I hope I haven’t missed the obvious due to not having coded in a while. Thanks in advance for your help :smiley:

I managed to fix the issue. Well, kind of a workaround more than fix it I believe but it works now.

I created a new function in my Global_Tick script that, when called, ran the GainHousing() method from the Population script via an instance of the Population script.

thanks for the help.

Based on the screen shots you shared.

Are you calling population.Gainhousing() further down the script shown that handles the GlobalTickfunction() ?

By what you’re describing and what you’re showing in the screen shots I think you’re calling the methods on different instances of your population class.

Firstly: make sure you are calling the GainHousing() function (can’t see it called in the pictures provided). Otherwise housingNode will always equal zero.

Second: where is your button pressed function? If it is inside Global_Tick, population.GainHousing() will work. Otherwise you need to go through your Global_Tick class variable. eg. Global_Tick.population.GainHousing().

Hopefully this helps!

I managed to fix the issue. Well, kind of a workaround more than fix it I believe but it works now.

I created a new function in my Global_Tick script that, when called, ran the GainHousing() method from the Population script via an instance of the Population script.

thanks for the help.