Is it possible to stop the execution of an event script or exit early without disastrous side effects?
For instance, I have a few IF statements and would like to exit the script if any of them return "True", rather than attempting to nest them in the correct order and break up the finishing code...
That's best practice. And, of course, you can return on false or any other condition.
I recommend Why you shouldn't nest your code on Youtube. It's not written specifically for Python but the principles are the same and it might just revolutionise your coding style.
Let's say button click event:
if a = 1:
send message to user, wrong number
exit event script...
if b = 2:
send message, wrong number
exit event script
Add a few more if's
If the code makes it through the above checks,
then we should run the following code:
do lots of stuff
exit event naturally
How can I exit/end event on line 3 instead of at the end of the code? That's what I'm looking for
if a == 1:
# send message to user, wrong number
return
if b == 2:
# send message, wrong number
return
# Otherwise ...
Note well the use of the == equivelance operator rather than the = set operator. There's a big difference.
1 Like
I just got return
from that video and put it into the code, lol.
Thanks!