New in ChoiceScript: *create_array, *temp_array commands, *page_break_advertisement

The latest version of ChoiceScript up on Github now includes some new commands.

  • *create_array: This command is a shortcut for typing *create a bunch of times. You give it a length and a value for all of the variables, like this: *create_array attributes 5 50 and it will behave as if you’d written this:

    *create attributes_1 50
    *create attributes_2 50
    *create attributes_3 50
    *create attributes_4 50
    *create attributes_5 50
    *create attributes_count 5

    You can also provide values for each of the variables, like this: *create_array attributes 5 10 20 30 40 50.

    *create_array can really come in handy with array brackets. You can put square brackets after the name of a variable, like this: foo[1] , to refer to the variable foo_1 . But you can put anything in the brackets, including variables, like this: strength[current_opponent] .

    *create current_opponent 1
    *create_array strength 5 50
    *create_array damage 5 20
    You did ${damage[current_opponent]} points of damage.
    *set strength[current_opponent] -damage[current_opponent]
    *goto dialog[current_opponent]
    *gosub_scene dialog[current_opponent] took_damage
  • *temp_array: This command is just like *create_array, above, but it uses *temp instead of *create.

  • *delete_array: It’s like *delete, but it deletes an array instead.

  • *page_break_advertisement: This command behaves just like a *page_break. When we publish the game in a native app on iOS or Android, the button will say “Watch an Ad to Continue” and will show an ad before showing the next page. (If the player has purchased the game, the button will just say “Next” and will function like an ordinary *page_break.)

    You can use *if choice_is_advertising_supported to detect whether advertising is supported on the current platform. (But, when testing on your computer, you’ll find that choice_is_advertising_supported is always false.)

  • *finish_advertisement: Like *page_break_advertisement above, *finish_advertisement behaves like *finish, but when we publish the game, the button will say “Watch an Ad for the Next Chapter,” and show an ad, if the player hasn’t purchased the game.

Big thanks to @CJW for doing the work of implementing *create_array and *temp_array. CJW did that work years ago :flushed: and I kept dragging my heels on finishing the work and delivering it. But it’s ready now!

(Similarly, the array brackets syntax was sort of announced years ago, but at the time, I said it was “experimental” and I’d never officially published documentation. It’s officially official now.)


This is great!

1 Like

So we don’t have to create random values and have formulations to activate event based on the result.
I used to create temp and than random die values so when dice rolled it will act on the result like tabletop board games logic.

The arrays are like in js arrays
So bracket numbers act as index.numbers.
Also can we have array.length logic to optimize even further?

Edit: I am asking for array.length because authors can use it like thia,

Create_array footsoldier1

Create_array footsoldier 5

Consider logic;
If create_array.length > 5
Goto label overrun
Goto label counter

Just a method I thougt while reading. I believe many usage logic will be found as well.


Nice. I’ll try this for my big RD content patch.

I don’t suppose *create_array supports creating two-dimensional arrays? That syntax looks like it excludes that possibility.

Also, how are *delete and *delete_array supposed to be used?

Awesome! When will this version of Choice Script be included with CSIDE? Also, are these featured usable in production now or should wip games refrain from using them at the time?

Congrats @CJW! That was an amazing contribution :partying_face:


yooooooooooo this is excellent

@CJW you definitely deserve “a raise” for this (heh)


Oops, I forgot to mention, *create_array does create a count variable also. I updated my post.


In my experience, they’re rarely used, and really only useful for *temp variables.

1 Like

Truly ecstatic to finally see this land. I hope it can help simplify many a startup.txt file! :wink:
Thank you for being open to (and tidying up) this contribution @dfabulich!

Sadly not. You can use create/temp_array to extend an existing array into two dimensions:

*create_array player 5 ""
*create_array player_1_attribute 2 "strength" "wisdom"
*create_array player_2_attribute 2 "strength" "wisdom"
*create_array player_3_attribute 2 "strength" "wisdom"
*create_array player_4_attribute 2 "strength" "wisdom"
*create_array player_5_attribute 2 "strength" "wisdom"

But unfortunately there is still some repetition (much less than before though!).

*delete my_variable
*delete_array my_array

Trying to refer to those same variables after such a command is used will cause a ‘non existent array/variable’ error. As Dan mentions above, there probably isn’t very often a practical use for them.

Awesome! When will this version of Choice Script be included with CSIDE? Also, are these featured usable in production now or should wip games refrain from using them at the time?

Maybe this weekend…? ASAP, certainly!


We’ll also have to wait a bit for @dashingdon to be updated to support these commands.


This is an incredible QoL improvement — can’t wait to yeet 200+ *create lines from my startup file.

Does the length parameter accept any expression that evaluates to a positive integer? Would

*create_array pc_skills (num_skills[{pc_class}] + num_bonus_skills) ""

be valid?

1 Like

No. *create commands can only use strings and numbers, because if the player starts playing your game, pauses for a while, and then upgrades to a newer version with a new stat, the newer version must provide a static value for the stat.

So *create constitution 50 is fine, because if we have to create constitution in the middle of the game, we know what to set it to: 50. *create constitution ((strength + dexterity) / 2) isn’t allowed, because it’s not clear whether we’re supposed to use the player’s current strength and dexterity values, or the original values, or the new starting values (if they’re different).

I think it might make sense to allow *temp_array to have a dynamic length, but it doesn’t do that right now.


Awesome. Thanks @CJW. You just made life easier for everyone.

1 Like

I hope to have time this weekend to update the code base to the latest version and re-implement the dashingdon API.


@CJW you’re great. :clap:

By the way, do these commands work in the online, browser based choicescript ide ?

1 Like

They will after the weekend :relaxed:


This is awesome! Thanks @both of you, this is really useful.

Is it recommended to use *delete/*delete_array? Are there known performance issues with creating arrays and not deleting them?

1 Like

6 posts were split to a new topic: Deprecate *fake_choice?

As promised, CSIDE now supports these commands: [CSIDE] The ChoiceScript IDE (v1.3.3 Now Available — 05/09/2022) - #1189 by CJW