Oh!!! I can keep my original code. All I have to do is add:
*create null 1
It is never actually used but fools the QT that everything is all right. Back to the elegant code. Thanks all!
current_learning contains “Biology”
and Biology contains 0
how about use double bracket instead of one?
because you’re trying to overwrite the value of biology, not the value of current_learning
*set {{current_learning}} %+ology_change_mid
That is what I was trying to say.
(Although I would rather call it something else than null just to be on the safe side, but that may just be my programmer brain.)
You’ve got it pretty much correct.
When CS sees curly brackets ({}), it essentially evaluates what's inside, then replaces the entire thing with the results of the evaluation.
| You Write | What ChoiceScript Understands | Therefore, CS Executes |
|---|---|---|
*set current_learning + 1 |
No curly brackets to evaluate. | *set current_learning + 1 |
*set {current_learning} + 1 |
{current_learning} means look at the value of current_learning. current_learning is History. Replace {current_learning} with history. (Variable names are case insensitive in CS. You can write History, HISTory, HiStOrY or any combo in between, but CS will treat it as lowercase.) |
*set history + 1 |
*set {{current_learning}} + 1 |
{current_learning} means look at the value of current_learning. current_learning is History. Replace {current_learning} with history. Now we have {history}. {history} means look at the value of history. history is 0. Replace {history} with 0. |
*set 0 + 1 |
But it doesn’t have to be a single variable name within the curly brackets. So
can be reduced to
*set {"photosubject_"&photo_count} current_exhibit
if you like.
However IMO, array syntax is even easier.
I don’t know if you’re familiar with “arrays” in CS, but they aren’t anything like real arrays in other programming languages (hence the scare quotes). “Arrays” in CS are just a shorthand way to add "_" + whatever expression you put between the brackets to a variable name.
Examples
| You Write | Where | ChoiceScript Sees |
|---|---|---|
boop[boop_count] |
boop_count = 13 |
boop_13 |
boop[9000] |
boop_9000 |
|
boop["lorem_ipsum"] |
boop_lorem_ipsum |
|
boop[boops_enabled] |
boops_enabled = true |
boop_true |
boop[(((11+{current_learning})&"${current_learning}")&{current_learning})&{{current_learning}}] |
current_learning = "History" and History = 50 |
boop_61history5050 |
(Notice &{current_learning} and &{{current_learning}} both append 50 onto the variable name. Recall {current_learning} is evaluated by CS as History, so it’s really saying &History – append the value of the variable History. Meanwhile, {{current_learning}} evaluates as 50, which ChoiceScript treats as a normal number because it knows it’s not a variable; variable names can’t begin with numbers.)
So assuming you have
*create nostalgia_whales 0
*create nostalgia_dinos 0
*create current_exhibit_var "whales"
you can increase nostalgia with
*set nostalgia[current_exhibit_var] +1
And for your photographs, you could use
*create photosubject_1 ""
*create photosubject_2 ""
*create photosubject_3 ""
*create photosubject_4 ""
*create photosubject_5 ""
*create photosubject_6 ""
*create photo_count 1
*create current_exhibit "dinos"
*set photosubject[photo_count] current_exhibit
There are some places you do need to spell out "array_"&index explicitly (like if you want to pass an array as a parameter to a subroutine), but for the most part you can use [] just about everywhere.
Wouldn’t {current_learning} become Biology, then {Biology} become 0, and then 0 is not a variable?
This was tremendously helpful. Thank you. Btw, how did you create that within this forum?
When I started build Exit I used arrays. But then I quickly found that CSIDE was failing my QTs. I was told by someone here it was because they could not process arrays. With that understanding I move passed them. Do you think I was mistaken? If I could get them to work, and learn how to implement them, they will be tremendously valuable I suspect.
It’s entirely up to you – what works best for your process is the best way to code anything when it comes to CS, IMO.
I don’t remember CSIDE QT not being able to process arrays, but I don’t use QT that often and I haven’t used CSIDE desktop since moving to a Chromebook.
Is it for sure the arrays causing the problem in CSIDE QT?
If you want to use arrays and don’t plan to use QT too often, you can run tests using your own copy of ChoiceScript: Testing ChoiceScript Games Automatically - Choice of Games LLC
If you mean the tables, Discourse (the forum software this forum uses) accepts markdown table formatting.
You can make a simple table like so:
| header 1 | header 2 | header 3 |
| - | - | - |
| cell 1 | cell 2 | cell 3 |
| header 1 | header 2 | header 3 |
|---|---|---|
| cell 1 | cell 2 | cell 3 |
For more complex tables, I find it easier to generate them in a tool like this Markdown Tables generator.
For folding sections like this
you can use BBCode style tags (conveniently available if you click the gear icon in the text editor)
[details="Summary"]
This text will be hidden
[/details]
or HTML style tags
<details><summary><big>Big Summary</big></summary>
This text will be hidden
</details>
I prefer HTML style tags because they give you more freedom to format the text in the summary or hidden section.
Discourse formatting isn’t super well documented, but the Forum Formatting Commands thread is a good starting place.
