Feature Request: Improved Arrays

I was certain there had been a thread for this, but search is letting me down.

That said:

If possible, could we have improved arrays? Coding in Twine Sugarcube introduced me to what arrays can do, and especially for immersion into the games it’s amazing.

Arrays as in Sugarcube allow to check for a big variety of values all at once, which I wouldn’t know possible with CS’s arrays.

And example:

In Sugarcube checking for names (to check if the MC has the same name or a variety thereof as an NPC) is done via a simple check if a string value is included in the array.

<<set $artommy to ["tommy", "tommie", "tommi", "tomas", "thomas", "tom", "thom"]>>

and 

<< if $artommy.includes($name.toLowerCase())>>

This is all it needs in sugarcube to do the same as what in CS requires this:

*if ((((((("$!!{name}" = "TOMMY") or ("$!!{name}" = "TOMMIE")) or ("$!!{name}" = "TOMMI")) or ("$!!{name}" = "TOMAS")) or ("$!!{name}" = "THOMAS")) or ("$!!{name}" = "TOM")) or ("$!!{name}" = "THOM"))

Especially for immersion (npcs acknowledging MC’s name sounds like XYZ, or to have it easier to avoid specific names/etc) this could be a blessing.

Thank you for listening.

8 Likes

Not to dismiss the request for native support, but in the meantime you could use the TEST_SOME cslib routine.

That’d look something like:

*comment check if artommy array contains name
*gosub_scene cslib_array test_some "artommy" "my_scene" "matches_name"
*if (false)
	*label matches_name
	*params value index
        *if value = name
	  *set cslib_ret true
        *else
          *set cslib_ret false
	*return

You can hide the “matches_name” function away in some utility scene and then it basically becomes just:

*gosub_scene cslib_array test_some "artommy" "my_scene" "matches_name"
*if cslib_ret = true
  artommy includes name

Maybe we could also add an easier to use “includes”, but we’d have to assume everything is a string. Food for thought @cup_half_empty.

2 Likes

I know of that, but it’s more about making it easier to achieve that without plugins. Saving on wordcount and all.
Nevertheless, thanks :3

1 Like