Jump to content

Recommended Posts

Posted

I hope my example tells you what I want to know. and how/can it be done. Thanks.

 

 

;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

EndIf

;I want to exit this function NOW and return to previous function

If Game.GetPlayer().GetItemCount(ThingThatWeneed) > 0; player has the thing that we need

; do all the stuff with the thing

EndIf

EndFunction

 

Posted (edited)
  On 8/12/2019 at 8:55 PM, Rasikko said:

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 Stuff

20 GoSub 100 go to line 100 and run sub-routine from there

30 Hi. Back from sub-routine are you

 

100 Do Stuff1

110 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 stuff

130 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 by antstubell
Posted

Use Return to exit early.

 

  Reveal hidden contents

 

 

You can also use Return to send a specific value if you design your function to do so.

Example

  Reveal hidden contents

 

Posted

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...