antstubell Posted August 12, 2019 Share Posted August 12, 2019 I hope my example tells you what I want to know. and how/can it be done. Thanks. ;this function called from within another functionFunction DoWeHaveTheThing() If Game.GetPlayer().GetItemCount(ThingThatWeneed) < 1; player does not have the thing that we need; show a message saying get the thingEndIf;I want to exit this function NOW and return to previous functionIf Game.GetPlayer().GetItemCount(ThingThatWeneed) > 0; player has the thing that we need; do all the stuff with the thingEndIf EndFunction Link to comment Share on other sites More sharing options...
Evangela Posted August 12, 2019 Share Posted August 12, 2019 Functions end when everything in their block has finished running. Link to comment Share on other sites More sharing options...
antstubell Posted August 12, 2019 Author Share Posted August 12, 2019 (edited) Functions end when everything in their block has finished running. Oh man!.Even in the 1980s Atari BASIC programming had a 'get out of sub-routine early' call. Would go something like this... 10 Doing Stuff20 GoSub 100 go to line 100 and run sub-routine from there30 Hi. Back from sub-routine are you 100 Do Stuff1110 Return If stuff 1 condition is correct/incorrect/etc go back to line after sub-routine was called (line 30) if not...120 … do more stuff130 Return All stuff is done go back to the line after sub-routine was called (line 30) I am gonna have to run a lot of functions if I can't exit a block early. Edited August 12, 2019 by antstubell Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 12, 2019 Share Posted August 12, 2019 Use Return to exit early. ;this function called from within another function Function DoWeHaveTheThing() If Game.GetPlayer().GetItemCount(ThingThatWeneed) < 1; player does not have the thing that we need ; show a message saying get the thing ;I want to exit this function NOW and return to previous function Return ElseIf Game.GetPlayer().GetItemCount(ThingThatWeneed) > 0; player has the thing that we need ; do all the stuff with the thing EndIf EndFunction You can also use Return to send a specific value if you design your function to do so.Example Bool Function DoWeHaveTheThing(Form NeededThing) If Game.GetPlayer().GetItemCount(NeededThing) < 1; player does not have the thing that we need ; show a message saying get the thing Return False Else ; no need to check again, either there is enough or there is not Return True EndIf EndFunction Function OtherFunction() If DoWeHaveTheThing(ThingThatWeNeed) == True ;do stuff with the thing EndIf EndFunction Note by setting up parameters for your functions you can reuse them with different stuff by passing in different values as needed. In this example DoWeHaveTheThing is reusable since any form can be passed into it. Link to comment Share on other sites More sharing options...
antstubell Posted August 12, 2019 Author Share Posted August 12, 2019 Ah, I see RETURN still lives. Thank you. Link to comment Share on other sites More sharing options...
cdcooley Posted August 13, 2019 Share Posted August 13, 2019 Note that the really critical part is where you would choose to return. In your original code you indicated you wanted to return after the first if-endif statement. That would have meant that the second one would never even be checked. IsharaMeradin's code uses the if-elseif-endif structure and corrects the potential problem by including the return inside that first if section. In that example the return isn't actually needed since the elseif will also effectively tell the game that the function has nothing more to do when the first if condition is met. Link to comment Share on other sites More sharing options...
antstubell Posted August 15, 2019 Author Share Posted August 15, 2019 I get it. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts