Hey, I have an integer index that I’m incrementing and performing checks based off the value of the int.
if (Index == 1)
{
}
if (Index == 2)
{
}
etc.
The index is incrementing properly and each check works by itself but when there are two of these checks in the same function the 2nd wont work. If I replace one of the checks with a boolean the other integer check will work. I tried the index as a float but same issue and the index is not a local variable.
Any help is appreciated
Sorry for the awkward names I’m just testing things quickly. All of the Nams are montage section names. I looked at your message, looked back at the code and instantly saw it, the brackets before and after the second index. It’s working now but let me know if anything is off because I’ll be adding more conditions.
It’s easier to post code in a code block here (see the < / > icon when writing the reply).
What looks off (even if all works fine), is that you are using
if (X == 1) {
}
if (X == 2) {
}
instead of “if else”.
More common is to use a switch.
switch (X) {
case (1):
// Do stuff
break;
case (2):
// Do stuff
break;
default
check(false);
}
I added the assert check(false) on the default there so that unimplemented indexes will crash intentionally.
Next up you are switching again using strings (“Start2”) etc which can easily be typed wrong. If the strings in your assets change, your code will still refer to the outdated string as well, leading to bugs or worse without notifying you.
You can also not implement a switch using strings or names like we did with the int. If possible it’s better to do implement those string switches differently.
I don’t know about that, first time I see montage code in c++. If you find a way not to hardcode the sections like this in code (but inject them, or point to), then that would be a best practice.