*gosub_scene scene_name label_name
@Jacic Right, like @Nocturnal_Stillness says, *gosub is useful whenever you have repeated text in multiple places, but then the continuation of the sequences are quite different. The repeated text could be in the same scene, or a difference sceneā¦Like so, in the same scene, to use a short example:
Finding yourself once again in a daisy garden, you feel a distinct clench of hesitation.
*choice
#Carry on boldly ahead to the rose garden.
*gosub daisy_descrip
whistling a jaunty tune. Eventually, you find yourself amongst the blood-red roses.
*finish
#Head through the daisies, but go directly to the garden shed where we keep the weed killer.
*gosub daisy_descrip
hands and arms well close to your sides and scarf carefully tucked beneath your jacket. They'll not get you this time, not before you get to that weed killer.
*finish
#Go hide under the bed.
It's a quick walk back up the gravel drive to your cottage. You proceed to the bed immediately, crawling beneath it.
There's a spider under here. You name it Harry.
*finish
*label daisy_descrip
The daisies are much like you remember them: white, lacy, and full of teeth. You keep to the path,
*return
I find I use it a lot for descriptions that can appear in more than once place, or in short sequences that you can access from different paths (like NPC conversations).
To grab text from a difference scene, instead of from within the same scene, youād want to code it like @RETowers has (plus a *return
after the section in question).
Using *gosub
is also nice when editing because then youāre only checking the same passage once, and only changing the same passage once, which is much quicker and also gives less room for errors. Trying to make consistent edits in 10 copy-pasted sections of code is more difficult (or Iāve found it so, anyway).
Ah now I get it, thanks everyone! I couldnāt for the life of me work out why gosubs were better for some things instead of gotoās. Probably because itās rare Iāll have the same section available in multiple sections as just a snippit to then return Iāve never seen the need for it. But maybe Iāll try it out now that I get it
Hi, one question, is the *return ignored if I use a *goto to go to this label instead of a *gosub?
@GoldenSilver No, youāll get a bug: āweāve already returned from the last gosubā
Iāve accidentally used goto instead of gosub before, and it took me a while to figure out what was causing the bugā¦
Hi. Ah I see, I havenāt tried using the *gosub yet, maybe I should have lol. I got like this big section of code for preset names that maybe could have used such a thing.
Iāve not been religious about it, though XoR 2 will have less of it. For non-programmers like me and others weāve heard from upthread, it takes effort and time to use functions like gosub and multireplaceāboth in figuring out how to use them in the first place, and then in being able to read and check the code that results. Thereās a real inefficiency there for anyone who doesnāt take naturally to computer code, manifesting in games that take longer to finish.
And ChoiceScript is meant to be a language for folks like us. That was the point, right? There were already plenty of ways for people with more programming nous and experience to write IF. The new thing about CS was that anyone could use it, even if they didnāt understand a scrap of the underlying software. Iād be really wary about pushing CS authors toward using things they donāt understand, and I think an insistence on gosubs does that. You can write a great game without any of those coding efficienciesāas witness Community College Hero, or Choice of the Dragon.
I use lots of gosubs, these days, but there are still some areas where I went with a stretch of repeat text with slight variancesāfor those whoāve read XoR or its code, Iām thinking particularly of the introduction to the Ledge of Bees scene in Chapter Four, which then feeds into a bees gosub. The intro pops up in around five slightly different versions around the chapter, with variation in different bits of the para depending on what brings you to the ledge.
While Iām sure I could have done the job with gosubs, it would have reduced the legibility of the code to me, making it harder for me to confirm that each intro made sense in its context. So I resorted to good old cut and paste where I could read the variation in whole-paragraph form.
Rather than trying to force authors to code as efficiently as possible, Iām sympathetic with MeltingPenguinsā solution of just applying a discount rate to the published word count estimate when a game is really inefficiently coded. Iād be happy for XoR to be advertised as a smaller word count game; it would still be huge.
That way lies āhow much of the word count is really code anyway?ā A lot more of the XoR wordcount sits in lines with an asterisk up front than in repeated words.
Iām emphatically a non-programmerā¦I do really appreciate @CJW and others pushing me to be more energetic in experimenting with code, though; I personally find the *gosubs
and choppy strings of *if
s much less confusing than a bunch of similar passages in multiple places, both as an editor and as a writer. I donāt copy-paste at all, because it breaks my head more than the *gosub
s et al. Plus then I also donāt feel like I have a good handle on how much discrete text I have in a given scene.
I suspect in my case itās musician brain; Iām used to D S al Coda and three staves going at once and all that. But maybe Iām not the only one? Certainly some people, as you say, do have a much easier time with repeated text, but other non-native coders might find efficient coding is actually easier on the brain (and the edits). So Iām glad we have voices for both.
Quick headsup from my side:
After a good night sleep (still headachy) I tried the @{(gender_child_count = āpluralā) have | has } thing and it worked.
Thank you.
(not daring to try more then three options, though)
EDIT: the command doesnāt show up correctly in firefox when playtesting. it works on safari and when you play via dashingdon, though
Absolutely, and sorry if I sounded like I was trying to speak for all non-native coders aboveā¦ please read ānon-programmers like meā as a subset of all non-programmers, not an assertion that all of them are like me.
I agree, gosub may not be for everyone all the time. The two main uses being reduced bugs and increased readability, I could see someone unsure of the how or why ā or someone just overzealous about it ā ending up increasing bugs and reducing readability.
And trying to get an āaccurateā word count seems like it should be the least of anybodyās concerns. I leave full pages of *comments in the code at the beginning of really snarly chapters. Not doing that just to be more accurate in the word count would be kind of crazy.
And, good point about code being a real source of inflation relative to what a reader expects to be called words. Apparently 22,000 of my words are in gosub lines, for example (using the grep and wc utilities to count). And a whopping 62,000 are in *if or *else lines.
Haaā¦ glad you finally sorted it out.
Oh.
Maybe youāre using an outdated firefox? IDK whether this is the case, tho.
I love that your example scenes vary, but seem to always involve the killer flowers in some capacity.
I use safari. But a friend has the problem
Do you send a compiled .html file for your friend to run directly in their Firefox installation, or do you send the raw .txt files for your friend to render through their own ChoiceScript installation, or do they test your work through Dashingdon?
I ask because multireplace is a fairly new feature! It was added in May of this year. Thatās 2017 if anyone in the distant future is returning to this topic.
If your friend is using an earlier ChoiceScript installation to render your .txt files, the multireplace option will never work for them. As a dedicated Firefox user myself, Iāve never experienced any trouble with multireplace that wasnāt entirely due to my own typos and errors.
However, if theyāre testing your work through Dashingdon (or youāve sent them a compiled .html file that functioned correctly on your own computer) the age of their ChoiceScript installation shouldnāt be a concern.
Now, itās possible Iāve misunderstood the situation, and your friend is testing their own work rather than testing yours. In that case, Dashingdon should still render multireplace in their .txt files correctly. However, both compiling their own .html file and running the .txt files raw will produce the same result, which will depend on the age of their ChoiceScript installation. As I understand it, Dashingdon allows authors to upload either .txt files or .html files. It then renders .txt files with an up-to-date ChoiceScript installation, but does not update compiled .html files.
They test with the txt file. Iāll have them know. Thanks
O, @Minnow the great one
May this humble peasant summarize your wisdom into a single sentence?
āYour friendās ChoiceScript is probably outdated.ā
Thatās certainly true for me, and leads to a lot less āedit this mistake here, here, here, here, and here, [because youāve now carried it over to five places because you donāt use *gosub.]ā
I really do appreciate the cost of that, and the general benefits of gosubsāhowever long it took me to figure them out when they were first added to ChoiceScript. I get that every new code feature is there because it allows more efficiency in one way or another, even if I havenāt yet wrapped my brain around how some of them work. And as long as theyāre not mandatory, I think theyāre entirely positive; those who grasp them can use them.
The CoG contest (if Iām reading the rules rightly) has the right idea in treating efficiency as a qualifier on the length score, rather than scoring efficiency for its own sake. Absolutely, a really inefficient 125,000 word game should be scored as a 100,000 word game.
But if efficiency had its own dedicated 5% score, and a 300,000 word game that CoG might otherwise have published lost out because of the authorās penchant for cut-and-pastes, I would question whether the company had lost sight of a distinctive strength. Plenty of good authors are bad coders. ChoiceScript allows them to write a game, and CoG has prospered from selling them.
But if they removed that wonāt it would be unfair to those who knows how to code and it only have a 5% score so the other person is a good writer as well and the whole reason of hosting any contest is to find someone who is best at everything related to the contest and I think handing choice script is something that a CoG author should know.
( Sorry if sounds like rambling. )