So I’m very new to coding and I’m trying to both learn the choice script language AND write my first game at the same time.
My question is more related to how the code “looks” than how it works since, so far, it seems to work as intended.
My code looks like this:
After you regain most of your consciousness, you turn to the long mirror near the door of your room. A family heirloom, intricate wood decorated with golden flowers. Your parents insisted on giving you some of their “vintage” stuff, although you weren’t so eager to add trash to your room.
*if (job = “unemployed”)
Your roomates don’t seem to mind either, most of them being too busy with college work or their low paying jobs.
*line_break
*goto main01
*else
*goto main01
*label main01
You look at yourself,
Here, there is an extra dialogue line if the reader selects their “job” as unemployed. It works, it does exactly what it’s supposed to, but I was wondering if I overcomplicated it and there’s an easier way to type it? I know that we should use whatever coding “style” is better for us, but I also want it to be clean and easy to understand as I am a total beginner and more of a writer than a programmer.
IMO, if it works it works, especially as you are a beginner and more of a writer. Having said that, the two ways of doing what you want to do are the way you did it or using multireplace, have a look at that and decide if you like it better. Personally, I would stick to the way you did it.
As @YHGS said the way you’re doing it is perfectly fine and the other, more “programmer-like” way of doing it is using a multireplace. I personally like multireplace better, but I do have a programmer background.
Also I don’t think you need the else if you don’t have any text there and thus you can also remove the goto’s and the label, but again, the way you’re doing it is perfectly fine. Whatever makes it more readable to you is the way you should do it.
I added the else because I thought that it was always needed when adding an “If” statement, I’ll try removing it and see what happens! I’m following the CSIDE tutorial while I write my own story, so sometimes I get things a bit mixed up ^^’ not to mention I basically started learning it yesterday ahah!
You also don’t need to use line_break, and it’s best not to except in a few special cases (e.g. if there’s poetry in your game, or for stat screen lists). They don’t play well with screenreaders for the blind, and your game will in general be most legible if you just use normal para breaks (no special command needed, just hit enter twice).
So if you just wanted a bit of text to show up at the end of a paragraph if you’re unemployed, this would be the better way to do it:
[Text you see regardless of job...]
*if (job = “unemployed”)
Your roommates don’t seem to mind either, most of them being too busy with college work or their low paying jobs.
You look at yourself, [...]
That way “you look at yourself” always starts a new paragraph, while the if unemployed line fits with the previous one.
PS: I would caution against trying to figure out multireplace until you’ve figured out how to code without it. Have a look at other games’ code to figure out the basics – here’s Choice of the Dragon, replace “startup” in the url with the name of another scene to see it (lair, queenpolitics, clutchmate, etc. – you can see the full scene list in the startup.txt).
Omg thank you so much for telling me about the line_break thing! I was using it a lot and I didn’t see anywhere about it conflicting with screen readers (especially since I looked at code from existing games and it seemed others used it as much as I do)
I wish to make my game as accessible as possible, I’m also really glad I found out about it before having 1k words written down. Thank you again!
You’re welcome! But having just double-checked my sources, I find I’ve misremembered the screenreader problem. As you can see at the bottom of the wiki here:
it’s a double line_break, not a single one, that messes with screenreader function. Sorry for misleading you.
Having said that, I’d still strongly recommend against using line_break between your paragraphs. (Who have you seen who does that in their games, out of curiosity?) It’s much easier for most of us to read paragraphs that are set off by para breaks rather than ones separated only by line breaks – especially since ChoiceScript can’t indent the text it displays, so you can’t use the typical solution for helping readers of single-spaced paragraphs know when a new paragraph is starting.
I can’t tell you the exact titles since I’ve been looking at so much code in the last couple of days, I’m sorry.
Don’t worry about it, we all get things mixed up sometimes! My journey with choicescript being a prime example ahah.
Also, I followed your advice and my code looks much cleaner thank you so much again.