This is so simple it will make you laugh! [SOLVED]

…or cry… in my case.

The following doesn’t print anything in Unity iPhone:

var myName : String = "Ruben";
if ( myName == "Ruben" ) { print("That's Ruben!"); }

It’s driving me nuts.
However, the following prints even though it shouldn’t:

var myName : String = "Ruben"; 
if ( myName == "John" ){ print("Name is John!");}

Somebody shoot me…
Or tell me what’s going on :shock:

-TT

It must be something with your other scripts because I just tried those and they work fine. The first one activated and the second didn’t just like expected.

Just figured it out: for some reason the editor cached the variable to say ‘John’. That was my first value when I first made this variable.
Later, I changed it (in script).

I never touched the var in the editor, but for some reason it was cached there anyway.
Since I’m used to the current version of Unity and not Unity iPhone this caught me off-guard a little bit.

Ah well.

Thanks though!

-TT

BTW: I love ‘Do Hard Things’! Great book… and even better: written by a twin!
-TT

A public variable will take on the value that’s set in the inspector. The editor will remember that value even if you change it in code. Is it possible that this is what was happening?

No way. You must be making an error. Perhaps you typed something into the inspector for the myname variable. Make them private and it would fix that.

Once you make a public variable, it takes its value from the inspector from then on, not the script. Unity and Unity iPhone don’t behave any differently in this regard.

–Eric