antstubell Posted August 14, 2020 Share Posted August 14, 2020 I'm having issues with the use of 'return'. From what I have previously understood is that, for example, you have 5 IF conditions in a script to check and only 1 of them has to be met for a result. Each time this script is run all 5 conditions are checked like the example below. An Event Called Int iButton = MyMENU.Show() If iButton == 0debug.notification("You pressed 1")EndIf ElseIf iButton == 1debug.notification("You pressed 2")EndIf ElseIf iButton == 2debug.notification("You pressed 3")EndIf … and so on… Even if the required result is met at the second IF condition, the script will still check the remaining conditions. The next example below is what I beloved would 'get around' this. An Event Called Int iButton = MyMENU.Show() If iButton == 0debug.notification("You pressed 1")Return ElseIf iButton == 1debug.notification("You pressed 2")Return ElseIf iButton == 2debug.notification("You pressed 3")Return … and so on…Questions: Does 'Return' at the end of a condition bypass any remaining condition checks?Does 'return' send the script back to it's event beginning (waiting for something to happen)?Can somebody show me an example of a multi-condition script that uses 'return' of any other command to 'get out' of checking any remaining conditions?Thank you. Link to comment Share on other sites More sharing options...
Evangela Posted August 15, 2020 Share Posted August 15, 2020 (edited) Return does two things. For functions with return values, return will return that value(no pun intended). Int Function GetSum(Int aiNum01, Int aiNum02) Return aiNum01 + aiNum02EndFunction This also serves to exit/finish the function, the other thing Return does. For menus, return will exit the menu, all I understand with this one is like if you want to make a cancel button which closes out the menu all together. For multiple conditions, including nested conditions, it may not be necessary to use Return unless you need it as a failsafe. The function/event normally exits when everything in a given condition has been met, however if you believe there could be some reason it may break(debugging is basically trying to break it and then add a prevention method), you could use Return to force an early exit. For functions with return values, you can't just use return by itself, you have to return the value that the function expects. Some examples: if condition 1 == x ; something happens else ; something else happens ; function/event is exited here endif ------ if condition 1 == x ; something happens.. elseif condition 2 == x ; nothing happened in condition 1, something happens in condition 2 ; function/event exits else ; just in case nothing happened in condition 1 or condition 2, something happens here ; function/event exits endif ---- if condition 1 == x ; ... elseif condition 2 == x ; ... elseif condition 3 == x ; ... else ; ... endif return ; let's assume something was missed with entire condition tree and the function gets stuck ; return will exit the funciton I wish I could think of an actual "broken" scenario but this the best I could come up with. Edited August 15, 2020 by Rasikko Link to comment Share on other sites More sharing options...
antstubell Posted August 16, 2020 Author Share Posted August 16, 2020 The script I am attempting to use Return in just isn't working. Look at my most recent post please. Link to comment Share on other sites More sharing options...
cumbrianlad Posted August 16, 2020 Share Posted August 16, 2020 Edited to remove a misunderstanding. Apologies to antstubel. Link to comment Share on other sites More sharing options...
Evangela Posted August 16, 2020 Share Posted August 16, 2020 Pretty sure antsubell is referring to his recent topic, but I do appreciate your concern. :) Link to comment Share on other sites More sharing options...
cumbrianlad Posted August 16, 2020 Share Posted August 16, 2020 Thanks. I'll say no more at the mo. moi moi (told you it was the only Finnish phrase I knew!) Link to comment Share on other sites More sharing options...
antstubell Posted August 16, 2020 Author Share Posted August 16, 2020 (edited) I apologise if I have upset anybody, cumbrianlad tells me that I've upset Rasikko and has PMed me telling me his dislike of my attitude towards Rasikko. Rasikko I'm sorry if I have caused you any offence. Yes, I have multiple threads going as I have multiple problems. If I don't reply in what is considered an appropriate time then again I am sorry. I have an elderly mother who I have to watch out for, not an excuse - a fact I have to deal with.So again if I have offended anybody and it seems especially Rasikko - I am sorry. EDIT: My internet was down for a day as well which contributed to my late acknowledgment of your replies. Edited August 16, 2020 by antstubell Link to comment Share on other sites More sharing options...
Evangela Posted August 16, 2020 Share Posted August 16, 2020 That's fine but I REALLY didn't see any harm done with your post and it's clear you were talking about the topic with the video describing your problem, i.e. telling me to go take a look. Link to comment Share on other sites More sharing options...
antstubell Posted August 16, 2020 Author Share Posted August 16, 2020 Thanks Rasikko. You have been most helpful. Link to comment Share on other sites More sharing options...
cumbrianlad Posted August 17, 2020 Share Posted August 17, 2020 Sorry about that mix up. I can be a complete clown at times! In the words of Metallica: "Sad but true" Link to comment Share on other sites More sharing options...
Recommended Posts