I made it work, with a lot more lines, then I learned this interesting tools:

First of all, I can’t even start counting how many times I tried to do something like this

string myString;
int myInt;

myInt = myString  // <---- Error

if (myInt == 10)
{
     DoStuff();
}

What always happened was that I got an error (you can’t convert a string into an int. Or vice versa) and I tried to work around it.

But the solution was super easy:

myInt = int.Parse(MyString);

Understanding this is going to save me loads of headackes in the future.

I have been seeing expressions like this for over 5 years, without getting the grasp of it until today.

For me, finally learning that tiny bit of code was another success. This is it:

bool inputlIsValidLevelNumber = (input == "1" || input == "2" || input == "3");

I usually did such things like this:

bool inputIsValidLevelNumber;
if (input == "1" || input == "2" || input == "3") 
{
     inputIsValidLevelNumber = true;
}

That’s literally 5 times shorter! so to finally understand what that was ^^

edit:

Also! I learned how to save on potential errors by saving on (“cashing”?) an additional variable:

Being:
password = PasswordsLevel_1[Random.Range(0, PasswordsLevel_1.Length)];

Better than

rNum = Random.Range(0, PasswordsLevel_1.Length)
password = PasswordsLevel_1[rNum];
1 Like

Hey Manu,

You might also like to look at the int.TryParse method which can return a boolean value to indicate whether the parse was successful or not, rather than just throwing an exception if it fails.

Oh, and to answer your question, it’s “caching” although it is pronounced “cashing” :slight_smile:

Hope this helps.


See also;

Oh I see … “Caching” like cache. Awesome!

I am having a look to ‘int.TryParse’ but I don’t quite get it, will get back to it after some more lessons tho. Ty for the input!

1 Like

You’re welcome Manu.

The difference between int.Parse and int.TryParse is that the latter won’t through an exception error if it fails to parse the value. Instead, it returns a bool to indicate whether the parse was successful or not.

Privacy & Terms