Subroutines with arguments?


#1

Is it possible to make subroutines that take arguments and parse them with *gosub? If so, how?

Thanks.


#2

Well uh the subroutines are usually *gosubs? What do you mean by parse? Do you mean something like;

*if (choice1)
   Do this

Because if so, yes, yes you can. I generally advise people to use *gosub_scene instead though, and create a separate txt file, as that way you don’t have to copy paste the subroutine into every scene where you’ll be calling it, if you plan to use it more than once obviously. I don’t think you should be calling gosubs within gosubs though, that might mess with things, not sure. As long as there’s no *page_breaks in the second *gosub you’ll probably be fine though. But yeah, need more info on what it is you want to do exactly.

Edit: Nevermind, there’s no problems at all having *gosubs within *gosubs.


#3

do you mean something like

*set renown 50
You look in the mirror.

*gosub famous

So that's how it is...

*label famous
*if (author = "Andrew")`
  *set renown %+50
  *return
*else
  *set renown 0
  *return

? Then, yes


#4

No, it’s not.
You have to emulate argument/parameter behaviour with separately defined variables, like so:

*temp arg_1 5
*temp arg_2 4
*temp return_val

*gosub func_sum
${return_val}
*finish

*label func_sum
*set return_val (arg_1 + arg_2)
*return

You could also reset the argument values and check them under the label code (so you could throw an error if they’ve not been provided). You can do a lot more than you’d think if you’re willing to play around a bit, but no, there’s no native support for arguments.


#5

@CJWThanks. I’ll do that then.