Gosub across scenes

Does the *gosub command work across scenes? I am wondering because I would like to write a subroutine on my startup.txt that will perform certain time related checks that I can call at the beginning of each of my scenes. Before I get too involved in something that won’t work I thought I might ask if anyone has done this.

I had a similar idea and tried to make it work but we can’t gosub to a scene. There’s no gosub_scene command, and if you goto_scene and then gosub, you would have to store a variable to track which scene referred the user. You can’t *goto_scene {variable} either.

Would be a great addition to ChoiceScript.

Bummer! Back to the drawing board.

I ran into the same problem, forcing me to simplify what I was aiming for–which might be the precise reason why it’s not available (and in my case, probably for the best anyway!). Still, I can’t help feeling that the greater the flexibility of what we have to work with, the better the end result might be.

Maybe simple is better, but you’re right it would be nice to have. Oh well I may just have to rethink what I was trying to do.

Okay, here’s a possibility if you really want to use it: Put your subroutine in it’s own scene, then make two variables, I’ll be calling them ‘return_to_scene’ and ‘return_to_spot’ Then, whenever you want to use the subroutine, *set return_to_scene to the current scene, and return_to_spot as a unique ID (I’d use ‘(scenename)id###’ or some variant of that) for that spot. Then send send the scene to the subroutine scene, with a label of the unique ID. Then a series of *if commands at the end of the subroutine can send it back to the right scene, and some *if commands at the start of a scene will send it to the right label. One thing: You may want to also make sure to cleanse (set it to some default state like ‘none’) the ‘return_to_spot’ if there is any possibility of reentering that scene, otherwise it may start sending you off to some label rather than starting from the top. Doing so in each *if command that uses it should suffice.

Now that’s probably more convoluted and complex than just having the subroutine in each scene, so, unless you really have an absolute need to, just copy-pasta it.

That is still a pretty inventive solution Reaperoa, I may have to try it out to see if it’ll work better than copy-paste. Thanks for that!

Seconded–many thanks indeed for this possible solution. I’ll certainly have to try this otherwise I’ll be copying a huge extra chunk into virtually every single scene, which just didn’t seem the right way to be doing things (even from my inexperienced viewpoint).

It does seem that ChoiceScript can be more versatile than I–and perhaps quite a few others–gave it credit for, which is good to know.

@reaperoa Just an addendum to this subject to say thanks, your solution works a treat. It took some tweaking to get it right but if I can do it, anyone can. :wink:

Only thing I would add if using this solution is to be careful of where & how you use temporary variables. Because you’re actually switching scenes, and then back again, temps set in the first scene will of course have been lost when you return and jump to a particular spot to continue.

Aside from that, it’s a great way of putting a huge chunk of often-repeated stuff in a separate scene entirely, rather than have to add it all into every single scene. The critical phrase here is “huge chunk”, however–if it’s not huge, it’s probably not worth doing it this way.

Which leads me to a question, out of curiosity–what’s the largest recommended size for a scene.txt? Anyone have any idea?

In The Race, the largest text file I had was only 65k. That was 1190 lines of code. I don’t think there is a recommended size as yet… although I’m sure some monster projects will emerge in time!

My newest scene is 278k and 3400 lines. I haven’t had any problems so far.

I don’t think ChoiceScript loads entire scenes, but instead loads them in chunks as it needs them. If that’s right, the whole concept of splitting the game into scenes is really just for the writer’s benefit as it would be able to handle scenes of any arbitrary length.

1 Like

I believe reaperoa may be right, my entire character creation section was in one large scene, until I split it up to save my sanity,i don’t remember the size of it but it was a monster

Thanks guys, that’s very reassuring. I noticed a slightly longer-than-usual stuttering with a 200k one online, when switching to stats and back again, but only occasionally. I wasn’t sure if I was pushing some sort of unknown limit, but it sounds like it was probably just the net at that time.