Using Lists in Choicescript

Is there a method for using a list/array in choicescript? Or, is there a way to export a javascript list into choicescript code?
I’m very curious, thank you.

@ TIYF I’m not sure what you’re meaning. What are you needing it for?

I don’t think there is any list function in CS, no. But! You CAN use Javascript in the code by using the *script command. I don’t know how that works exactly, or if using a js list would even be possible, but hopefully that helps?

They’re called arrays in Javascript and whilst you can emulate some array-like behavior via concatenation, there are no native commands or support for it.

You could also as @SpaceLesbian said use and manipulate JS arrays via *script - though as usual, be advised that no one is really sure on if or how that will effect your game’s publication.

@CJW But, if I was to create an array through the *script command, how could I then refer to it for the game. Is it possible to say make an array like

*script array = [1,2,3];
*script x = array[0];

And then bring the x variable into a format that choice script can recognize?

May I ask what you want to use arrays for? You may find that there is an easier way to do what you’re attempting.

You will be able to pull values from an array into choicescript, but you won’t be able to pull the array itself, so the whole concept becomes pretty redundant.

*script this.temps.my_array = new Array(1, 2, 3);

That will just print the entire contents of the array: 1, 2, 3.
You can’t (in choicescript) specify the index.

To get a single index’s value you’d have to do something like this:

*script this.temps.my_array = new Array(1, 2, 3);
*script this.temps.my_value = this.temps.my_array[0];

Which just seems like a complete faff to me.

Can I recommend array emulation in plain CS instead?

I plan to use the array to speed up the process of randomizing player values. Say for example I have a value, like, name. I want a array of possible names, and then to have one of the values in that list to be randomly chosen, and then have that value represented in choicescript.

EDIT: Therefore, I don’t believe what you’ve referred me to regarding array emulation would quite work. Rather, could you direct me to a tutorial, or explain yourself, as to how specifically the *script command works, since it seems you have to write a certain method to use the command.

Meaning the
*script this.temps.my_array
section of your code.

EDIT: By “speed up” in the first paragraph, I mean rather to ease the process of writing the code. Instead of have a random number generated between say 1 and 100, and then writing 100 if statements to simply tell which name was generated.

Not to casually brush you off but it’s a huge, convoluted topic which is hard to teach and explain; JavaScript is a whole new language itself and one fundamentally more complicated than ChoiceScript at that.

Hence why in the rules section it states “This is not a forum for discussion about JavaScript and COG does not support the use of *script”.

I won’t say anything more than *script allows people who already know some JavaScript to execute snippets of it during a choicescript session.
If you want to use script, you’ll need to go learn javascript.

Anyway emulated arrays will work just fine for this, @FairyGodFeather made a random name generator a while back and I converted it to fake arrays, I recommend using those as a reference.

FTG’s thread:

Randomized name code (via fake fake arrays):

There’s a fair chunk of code in that link but really all the complex/randomizing stuff is done in this block:

*label generate_names
*temp count 0
*temp pointer 0
*temp last_names false
*label name_loop
*set count + 1
*rand pointer 1 25
*if (last_names != true)
	*setref ("rand_name"&count) {(gender&"name_")&pointer}
*if (last_names)
	*setref ("rand_lname"&count) {("lname_")&pointer}
*if (count != 4)
	*goto name_loop
	*if (last_names != true)
		*set count 0
		*set last_names true
		*goto name_loop
		*set last_names false
		*goto name_choice

The rest is just code to populate the choices on the left, but presumably you’ll want to incorporate your own methods for display/selection.