Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow complex lengths for temp_array #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

CareyJWilliams
Copy link
Contributor

@CareyJWilliams CareyJWilliams commented Nov 3, 2024

Recently I've found myself often wanting to temporarily copy arrays in ChoiceScript to do some changes without affecting the original array. It's a bit more awkward than it needs to be at the moment because temp_array doesn't accept a complex length. I understand why create_array doesn't, but I don't think this restriction is necessary for temp_array?

Usage

*create_array my_global_array 5 1 2 3 4 5
*temp_array my_local_array my_global_array_count 0
*comment you can now loop to copy safely

An alternative, more specific approach, might be a whole new command, something like:

*create_array my_global_array 5 1 2 3 4 5
*temp_array_clone my_local_array "my_global_array"
${my_local_array[3]} == 3

Cleaner but less flexible. Allowing temp_array to take complex values also opens up a lot of options for dynamic variable creation (combining multiple arrays etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant