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:
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 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.)
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,
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?
Truly ecstatic to finally see this land. I hope it can help simplify many a startup.txt file!
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:
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?
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.