New ChoiceScript features for programmers

Oh, yeah, I forgot about that completely. (I never documented it; I don’t think anybody’s ever used it.)

But it’s working again in the latest ChoiceScript up on github.

1 Like

I think it’s a useful feature, but true, I don’t think many people are aware of it.

Are square brackets okay to use? Apologies if I missed more recent posts on square brackets. I’m integrating some code I designed last year and having problems I don’t remember having when I last tested it.

My example is my line:

*gosub_scene phrase/adjectives weather[random_noun]

throwing up the error:
‘phrase/nouns line 148: Invalid expression; expected name, found OPERATOR at char 7’

What’s up with the division sign in the code?

nested folders

I thought we were only supposed to have text files in our scenes folder, and not other folders?

Works great. Picked it off a forum post a while ago because I had way to many files in there. Downside is its not compatible with some CSIDE features, so I don’t recommend using it.

Normal use example without square brackets: *goto_scene territory/two_kingdoms_riverrun_waybrook

But if you saw an official post saying don’t use them I’d appreciate a signpost…

Yea, that’s actually not an intended feature, and isn’t supported. (And I’d probably have to say to undo it for publication.)

1 Like

Thank you! Have removed all folder nesting and it runs without issue.

1 Like

To add: that is exactly why it is not compatible with CSIDE :slight_smile:

1 Like

Not sure if this has been suggested before, but I would love an option to turn choice trees into single-click affairs. Let me explain what I mean by that.

Here's a standard screenshot:

If we let each one of these choices function as clickable objects, we may be able to eliminate the need for the Next button altogether (this is a suggestion for a toggle in the options menu):

Screenshot

Of course, the finished product would not say “single click” – that’s just for illustration purposes. Etc.

2 Likes

For safety measure, I think a “double click” feature is more useful.

Single click to select, click again to confirm.

There is already a “swipe” option on mobile devices (not sure if this works on PC?), which I think is a safer alternative to what you’re proposing.

1 Like

So I have found some strange behaviour while using arrays, or maybe I’m just doing this wrong, I don’t know.

In my game I have two arrays that deal with the primary and secondary weapon the player is using; “primary_wep” and “secondary_wep”.

In scenes where I need to check what the player is using, I need to check which one is equipped, but I also use different descriptions based on if the weapon has full automatic capability. I end up with this:

(param_1 is a boolean that controls if the primary or secondary weapon is to be used, based on when this *gosub is called)

(“item_fullauto” and “item_short_name” are just number variables that are valued 7 and 14 respectively (just as an easier way so I don’t need to remember what index holds the full auto status and the short name of the item))

*gosub wepTeste true

*label wepTeste
*params
*if (param_1)
	@{primary_wep[item_fullauto] With several bullets coming out of your ${primary_wep[item_short_name]}, your target is pushed backwards by each, falling down on the ground|Once the sights are perfectly aligned with his chest, you open fire; he falls down soon after}.
*else
	@{secondary_wep[item_fullauto] With several bullets coming out of your ${secondary_wep[item_short_name]}, your target is pushed backwards by each, falling down on the ground|Once the sights are perfectly aligned with his chest, you open fire; he falls down soon after}.

So I wanted to simplify that and avoid the repeated text as well, so I thought of just making the param_1 be the name of the array itself, like “param_1” which would then be received and used, as in:

@{param_1[item_fullauto] With several bullets coming out of your ${param_1[item_short_name]}, your target is pushed backwards by each, falling down on the ground|Once the sights are perfectly aligned with his chest, you open fire; he falls down soon after}.

That’s when I started to run into problems, as CS doesn’t seem to read “param_1[whatever]” as an existing variable (I get errors that param_1_x) doesn’t exist as a variable. I tried a bunch of things like surrounding param_1 in { } (like ${{param_1}[3]}) but I couldn’t get it to work. In this case it would give me an error saying “primary_wep” variable doesn’t exist, and ignore the braces right after it.

After some digging around I noticed that there was an older way to call arrays, using for example:

(going for position 3 in the array, such as param_1[3])

@{{param_1&3} Blue|Green}

When I did it this way, it worked (in this case I set both “primary_wep[3]” and “secondary_wep[3]” to be booleans, and it worked just fine giving me either Blue or Green), but I wonder if this is normal behaviour or am I just calling it wrong?

(I also had to set the incoming array name to have an underscore at the end, like “primary_wep_” or “secondary_wep_” instead of just “primary_wep” or “secondary_wep”)

Using a variable in place of the position such as:

*temp aaa 3
@{{param_1&aaa} Blue|Green}

Will also work, but I had problems as well with arrays with more dimensions (such as “array”) if I tried this format; I could only get it to work in single dimensional arrays.

In the end, this would probably work, but is it the right way to do it?

*gosub wepTeste "primary_wep_"


*label wepTeste
*params
@{{param_1&item_fullauto} With several bullets coming out of your ${{param_1&item_short_name}}, your target is pushed backwards by each, falling down on the ground|Once the sights are perfectly aligned with his chest, you open fire; he falls down soon after}.

Hi all. What’s the status of the experimental array? I found this post, but arrays are not mentioned in the dev guide.

BTW, I was able to “emulate” arrays using a sequence of variables named array_0 array_1 array_2… then using another variable to create a name to read/write.

*set varname (“array_”&x)
*if {varname}

I’ve been using them for every pronoun in my CoG title, so I think that’s just a 5+ year old warning that’s never been updated.

CS doesn’t support arrays, lists, tuples or any collections per se. But just like you did, it’s possible to emulate it by preemptively creating a variable for each slot.


You can call it between brakets:

if array[x]
      etc

No need for an intermediate variable.

2 Likes

Is there any chance more in depth documentation for using these features could be added to the choice script wiki? https://choicescriptdev.fandom.com/wiki/ChoiceScript_Wiki

There was recently a call for volunteers to update the wiki here, if anyone wants to volunteer or list specific things they think should be added.

I started an article on arrays in the wiki.

3 Likes