How do I reference an incremented int with one button, that was incremented from another button?
So, I have a button that increments an int by 1 each click, using:
int EffectNumberCounter(int tempEffectNumber)
{
int effectNumberFinal;
effectNumberFinal = tempEffectNumber + 1;
return effectNumberFinal;
}
And then the button:
public void btnAddEffectClick()
{
effectNumber = EffectNumberCounter(effectNumber);
}
I want to reference the result of effectNumber, whatever it happens to be at the time, when I click the other button, which I have dubbed btnRerollEffectClick, by using if effectNumber = 1 (ETC ETC ETC), without losing the stored value of effectNumber. Unfortunately it keeps returning to 0.
What would be the way to do this?
Could you elaborate more please, i'm really confused on what is your goal here.
I want my second button to do something different based on the value of effectNumber, which changes each time I click my first button. But when I click on my second button, for some reason the value of effectNumber resets to 0.
The code for the second button click has an if statement saying if (effectNumber == 0) do thing 1 else if (effectNumber == 1) do thing 2 etc etc etc...
Well, just in those two parts of code you sent there's no reason for it to be returning to 0. Can you post the whole script or attach it ?
Answer by JunaidGhani · Nov 23, 2017 at 05:04 AM
i think you want an int from one function and use it as a reference in another. if my interpretation isn't correct sorry to bother you.
private Count;
int EffectNumberCounter(int tempEffectNumber)
{
if (Count > 0 // yourcondition){
int effectNumberFinal;
effectNumberFinal = tempEffectNumber + 1;
return effectNumberFinal;
}
else //Dothis
}
public void btnAddEffectClick()
{
effectNumber = EffectNumberCounter(effectNumber);
Count =effectNumber;
}
What is the difference other than adding an extra variable that is equal to effectNumber? Are you saying that the script won't store the value unless it's in whatever this "Count" function is?
Your answer
Follow this Question
Related Questions
How to use the results of a dice roll? 2 Answers
OnGUI will not show up? 1 Answer
Why isn't my object lerping ? C# 2 Answers
My audio doesn't play, I'm through my options... 1 Answer
Need help with c# 1 Answer