- Home /
The question is answered, right answer was accepted
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 :D
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:
http://imgur.com/AjYaDlA 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. http://imgur.com/R83xyod 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 :D
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.
Answer by pJaerlauncher · Oct 16, 2015 at 03:14 PM
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.
Answer by C_Randy · Oct 12, 2015 at 12:29 AM
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!
Sorry for the late reply. GainHousing() is called when a button in the UI is pressed.
Answer by Zephire · Oct 11, 2015 at 07:24 PM
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.
Sorry for the late reply. GainHousing() is called when a button in the UI is pressed.
Do I need to refer to this within my Global_Tick function?