# Params and "Non-existent variables"

**URL:** <https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252>\
**Category:** ChoiceScript Help\
**Created:** [June 14, 2025, 9:55am UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252 "2025-06-14T09:55:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zaleramancer](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/zaleramancer/32/253434_2.png) [@Zaleramancer](https://forum.choiceofgames.com/u/Zaleramancer)\
**Post date:** [June 14, 2025, 9:55am UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252/1 "2025-06-14T09:55:11Z")

</div>

Hi, I’m having trouble with the parameter commands! I was trying to adapt [this](https://forum.choiceofgames.com/t/using-rand-in-a-choice/94461/22) code to fit with the use of create array as an experiment and/or to familiarize myself with the code.

The exact error I’m getting is `Non-existent variable 'array_1'`

My code looks like this:

```choicescript
*create_array startingpath 3 "shadow" "bone" "eye"
*gosub shuffle "startingpath" 3

*label shuffle
*params array array_length
*temp i 1
*temp j 0
*label shuffle_loop
*if (i < array_length)
    *rand j i array_length
    *if (j != i)
        *temp val_i {array[i]}
        *set {array[i]} {array[j]}
        *set {array[j]} val_i
    *set i + 1
    *goto shuffle_loop
*return

```

The idea is to present a few possible paths forward in a forest, having them be randomized by the array, so that you are presented with a choice of two (as a simple proof of concept). Because of that, this is all in my startup.txt, and I’m not sure if that’s the problem?

The error occurs on the first line in which I use the “array” param- it parses array\_length fine, it seems, but doesn’t read the paramater that was supposed to be pushed to “array”, so it just reads “array\_X” instead of “startingpath\_X” as intended.

I’ve read the param documentation, and checked on here for other people with this issue, but the one I found was a problem with using camelcase, which I am not doing, so I’m lost.

---

<div class="post-metadata">

**Author:** ![Valda\_Reehux](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/valda_reehux/32/126891_2.png) [@Valda\_Reehux](https://forum.choiceofgames.com/u/Valda_Reehux)\
**Post date:** [June 14, 2025, 10:24am UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252/2 "2025-06-14T10:24:22Z")

</div>

I think you want to read what’s inside “startingpath\_1” and not “array\_1”

maybe you should read the inside of “array” which should be “startingpath” before combining it with [i] and [j]

> \*temp val\_i {array[i]}  
> \*set {array[i]} {array[j]}  
> \*set {array[j]} val\_i

should be somewhere around this part ✌

---

<div class="post-metadata">

**Author:** ![Zaleramancer](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/zaleramancer/32/253434_2.png) [@Zaleramancer](https://forum.choiceofgames.com/u/Zaleramancer)\
**Post date:** [June 14, 2025, 10:27am UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252/3 "2025-06-14T10:27:27Z")

</div>

That gives the same error as before, for me, in the same place.

---

<div class="post-metadata">

**Author:** ![Zaleramancer](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/zaleramancer/32/253434_2.png) [@Zaleramancer](https://forum.choiceofgames.com/u/Zaleramancer)\
**Post date:** [June 14, 2025, 10:45am UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252/4 "2025-06-14T10:45:20Z")

</div>

In an attempt to do some basic troubleshooting, I tried working with params on something very basic:

```choicescript
*gosub visit "Dracula" "garlic"

*label visit
*params person gift
You go visit ${person} and you bring ${gift} with you.
*return

*choice
    #yes
    #no
        
 *finish

```

This doesn’t work. It tells me that no parameters were passed. I used the example in the documentation about how to work with Param and Gosub, so I’m kind of at a loss as to what I’m doing wrong.

---

<div class="post-metadata">

**Author:** ![LiliArch](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/liliarch/32/120749_2.png) [@LiliArch](https://forum.choiceofgames.com/u/LiliArch)\
**Post date:** [June 14, 2025, 11:19am UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252/5 "2025-06-14T11:19:24Z")

</div>

> [@Zaleramancer](#):
>
> `*gosub shuffle "startingpath" 3`

I’m not sure why the debug test isn’t working, but I think there’s an issue with this line: “startingpath” is in quotation marks, so you’re not passing the variable, you’re passing a string.

---

<div class="post-metadata">

**Author:** ![Valda\_Reehux](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/valda_reehux/32/126891_2.png) [@Valda\_Reehux](https://forum.choiceofgames.com/u/Valda_Reehux)\
**Post date:** [June 14, 2025, 11:55am UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252/6 "2025-06-14T11:55:48Z")

</div>

![image](https://global.discourse-cdn.com/choiceofgames/original/3X/3/e/3e4457be58bbdf08fc7966ebc2457967f41e0c1d.png)  
tried it myself and it worked, however there is a slight difference,

![image](https://global.discourse-cdn.com/choiceofgames/original/3X/e/3/e38ecd15fafcc9eacfda9445e679dcb01fc2aff2.png)  
I don’t rename the passed parameters right at params command, instead I made my own temps with names that I wanted

to be honest I don’t use the renaming of param\_1, param\_2 often so I can’t answer why it didn’t worked

> \*create\_array startingpath 3 “shadow” “bone” “eye”  
> \*gosub shuffle “startingpath” 3
> 
> \*label shuffle  
> \ ***params array array\_length**  
> \*temp i 1  
> \*temp j 0

I suggest you try declaring array and array\_length not on params command, see if it works ✌

---

<div class="post-metadata">

**Author:** ![cup\_half\_empty](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cup_half_empty/32/273983_2.png) [@cup\_half\_empty](https://forum.choiceofgames.com/u/cup_half_empty)\
**Post date:** [June 14, 2025, 12:10pm UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252/7 "2025-06-14T12:10:39Z")

</div>

> [@Zaleramancer](#):
>
> This doesn’t work. It tells me that no parameters were passed.

Be careful where you place your subroutines. ChoiceScript reads top to bottom. Subroutines are just labels with a `*return` statement. ChoiceScript doesn’t distinguish normal labels from subroutine labels, so it will read every line of the file and when it hits the `*param` command it will thow this error. **Move all subroutines either to a different file or to the end of the file _after_ a `*finish` statement.**

> [@LiliArch](#):
>
> I’m not sure why the debug test isn’t working, but I think there’s an issue with this line: “startingpath” is in quotation marks, so you’re not passing the variable, you’re passing a string.

Actually, passing it as string it the right way.

> [@Zaleramancer](#):
>
> so it just reads “array\_X” instead of “startingpath\_X” as intended.

That’s because everything in ChoiceScript is a string. There’s no real array as you may understand it from other programing language. It’s just syntax sugar to creating many variables with a prefix. When you use array syntax, it just concatenates the names with an underscore. So `array[1]` is the same as `array_1`. It’s not going to parse `array` as a variable pointing to an array in memory (even because the array doesn’t exist).

To do what you want, you can’t use array syntax with reference variables, but instead do the concatenation manually (or use interpolation as below).

```js
// interpolation
*temp val_i { "${array}_${i}" }

// concatenation 
*temp val_i { (array & "_") & i }

```

---

<div class="post-metadata">

**Author:** ![LiliArch](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/liliarch/32/120749_2.png) [@LiliArch](https://forum.choiceofgames.com/u/LiliArch)\
**Post date:** [June 14, 2025, 12:39pm UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252/8 "2025-06-14T12:39:14Z")

</div>

> [@cup\_half\_empty](#):
>
> everything in ChoiceScript is a string

Grah, this just _keeps tripping me up_. (But isn’t it passing the _value_ of the variable to the subroutine? What good does giving it the variable _name_ as a string do?)

---

<div class="post-metadata">

**Author:** ![cup\_half\_empty](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cup_half_empty/32/273983_2.png) [@cup\_half\_empty](https://forum.choiceofgames.com/u/cup_half_empty)\
**Post date:** [June 14, 2025, 12:57pm UTC](https://forum.choiceofgames.com/t/params-and-non-existent-variables/170252/9 "2025-06-14T12:57:38Z")

</div>

Yes, you’re passing the values. In this case there’s no variable called `startingpath` because `*create_array` will create many variables with the prefix but no variable actually called “startingpath” (only startingpath\_1, startingpath\_2, etc). You want to pass it as a string so you can concatenate inside the subroutine.
