Is there a way to disable negative index loop? #5554
TheYellowArchitect
started this conversation in
Scripting
Replies: 1 comment 1 reply
-
No, the only way is to check: assert(0 <= i and i < array.size()) or if i < 0 or i >= array.size():
push_error("some error")
return some_default I also find this more error-prone than convenient. In my opinion, there should be a method ( |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Code-example:
I do not want this behaviour by default because when I code and an index is negative, I want the compiler to hit error, pause the game and highlight the line, so it's obvious a certain dynamic index is wrong. With the default negative loop index, errors like this pass unnoticed and are relatively hard to find within huge systems, where you will need at least an hour to find in a huge new system.
If I want to make negative looping for indexes, I can make an array wrapper function myself, I don't want this counter-intuitive behaviour for every array[] type in existence. It is common to use -1 for error/null indexes for example, but this destroys that practice.
Anyway, is there an editor settings option or something i missed?
Beta Was this translation helpful? Give feedback.
All reactions