A simple condition, it doesn't happen. Why?

if( value1 == 3 || value2 == 3)
{
// code
}

Additionally, I can say that the variables look like this:

[SerializeField] Text value1Text;
[SerializeField] int value1;
[SerializeField] Text value1Text;
[SerializeField] int value2;

void Start()
{
value1Text.text = value1.ToString();
value2Text.text = value2.ToString();
}

The values are added as shown in the Inspector directory, but after reaching the value of 3, the code is not executed. I also tried changing the operators greater than equal, but it did not give any result.

Hi,
Have you tried to debug log your values? That would be the first thing to do in any problem situation.

I don’t see any code above assigning a value back into value1 / value2.

Just assigning it the other way in Start() does not actually create a connection back the other way.

You can use int.TryParse( string text, out int value) to get an integer back from the string:

Yes, and the variables go to 3, but I have a second script in which I also use these variables so nothing happens anymore and I don’t know why!

Those values appear private to me. How is the other script getting those variables? Just declaring them in the other script simply makes brand new ones, even if they’re the same name.

@Kurt-Dekker ,
When this function was used, the values stopped increasing.

Yes, I know that, I tried to combine them, but for that I would have to use static values and that causes a lot of complications. So I created two new ones referenced by the same objects in Unity. However, objects added to the second script are not visible, even when ‘public’ is used.

I kinda got tired of handling this sorta multi-script scattered data hassle all over the place noise, so I wrote a package I call Datasacks and put it out for free. It’s overkill in your case, but Datasacks are a handy way to interoperate with data from any arbitrary scene or code or chunk of UI.

Datasacks is presently hosted at these locations:

https://bitbucket.org/kurtdekker/datasacks

Here’s sorta how it works:

8687265--1171653--20180724_datasacks_overview.png

1 Like

@Kurt-Dekker ,
I assume the problem is with the condition ‘==’.
Because if it uses another option, e.g. ‘! =’. Works properly.

Thank you for sharing this data, I will read it and use it in the future.

== is exactly the opposite of != so I’m not sure what value this will have for you.

did you do what Olmi said above and print the values out at the precise site you are comparing them? Are they 3?

I considered making a mistake in the code. However, the code was written correctly, and it works with a different condition. When: ‘value <= 3’, Unity sees the value and the code is executed. In the case of ‘value == 3’, it is as if Unity was omitting this value.

I am going to unwatch this post until I hear you have printed the ACTUAL values at the ACTUAL place you are checking them.

Good luck!

https://ibb.co/C8FtX1s

value1 and value2 are simply not reaching 3, or your check is happening in part of the script that does not get executed when they happen to reach 3.

How are these values (value1 and value2) expected to change? Being private, only a function in the same script could be modifying value1/2. Post your whole script.

2 Likes

I did as you said and you were right about the increase in value. However, the condition continued to become a problem.
In the script, I use two relating to these variables, one works fine, the other which I have already mentioned here does not. Why?

First relating: (What is strange !! When I was using || as or acted as and. The condition uses && as and and works like or.)

while(value1 < 3 && value2 < 2)
{// code}

Second relating: (Doesn’t work)

if(value1 == 3 || value2 == 3)
{
//code
}

If it doesn’t work, it’s because neither value1 nor value2 are 3. Use Debug.Log() to print their values.

2 Likes

I did it. First relating works fine but another not.

I put the condition into another function and it started working.