Couldn't extract another token (using #)


I’ve seen a few posts with the same problem in the forums, but none of the fixes seem to apply to my code.

I get this error:
functions/read line 8: Invalid expression, couldn't extract another token: ${lists_listname}#lists_char = "^"

And this is the code in question: (the lists_listname is defined/created/set elsewhere)

*temp lists_char 0
*temp lists_count 0
*temp lists_string ""
*label alpha
*set lists_char (lists_char + 1)
*if ${lists_listname}#lists_char = "^"
  *set lists_count (lists_count + 1)
  *if lists_count = lists_index
    *goto beta
    *goto alpha
  *goto alpha

*label beta


Would it work if it was lists_listname#lists_char = "^"?


When I do that it says:

functions/read line 8: Invalid expression at char 27, expected no more tokens, found: EQUALITY [=]

Also, I need it to compare the letter of the string inside of a variable that’s name is stored in lists_listname.


Well, you certainly shouldn’t have the ${} in there; that’s only for use within actual text; not for a command line.

Maybe you could try *temp letter lists_listname#lists_char, and then test letter against "^"?

EDIT: This might work:

(lists_listname#lists_char) = "^"


Hmm so is it impossible to compare the letter of the string inside of a variable that’s name is stored in lists_listname.?

When I did your idea, it work but I’m worried that I can’t get the output I want.


Isn’t 'lists_listname` the list itself? And wouldn’t it work better if it was?


The idea is that the function/read scene is just for running a custom function and the writer/coder never has to edit it. When they want to, they just change the lists_listname to the name of whatever list they want to, assuming they have multiple.


I think it’ll work just fine.

The [lists_listname] value will always be the [MyList], isn’t it?


Well, if they change it to a copy of the list, wouldn’t that work instead? (And be simpler than than trying to do pointers in CS…)

Looking at your other thread, it looks like that’s actually what you’ve done, here:

*set lists_listname MyLists


@Szaal @ParrotWatcher

I don’t think that will be easier.

No, it’s meant to be changed, which is why I wanted to use a pointer.


Why not? :confused:

CS wasn’t really designed for pointers, and while they can be used, it’s generally easier for the writer to just use the variables themselves.


Well it’s going to be like a thousand or so words of code for various functions and to copy that over and over again would be confusing and take up space. Though it could work as a last resort since the writer should only need a small handful of lists, for say inventory, appearance, wounds, etc. Technically they can all be put into one list… but first let me see if your earlier idea for sure doesn’t work.


@ParrotWatcher @Szaal okay, so parrot watcher’s earlier idea did work. (I think my last reply didn’t make since because it does need to work either way)

There are a lot more errors I’m sorting through but they seem simple enough. I’ve been working on this (with the help of you guys, thank you, thank you) for the past 5 or so hours.


IDK if this is the case, but your OR doesn’t need to be capitalized.
Just write…



Sure, but the list would be saved as a global variable, so there’s no need to use a pointer to reference it. Just set the test list to the list you want tested (which you look like you already do) and then call the function scene.


@Szaal @ParrotWatcher
I think it worked with all the pointers involved…
I have another error though that I don’t understand. It says:

line 21: There is no character at position 49. "^Blue^just growing out
^Dark^Light^green^freckled" is only 48 characters long.

Which should make since, but line 21 says:

  percent cha Charisma

(It’s part of a stat chart)

It should be talking about the stats scene but if it’s talking about the function/read scene, then line 21 there is:

*set letter lists_listname#lists_char

Which worked fine two other times previously in the same scene.
Edit: no other line 21 in any file is abnormal, and the stats screen loads everything it should, including the list items. So I think maybe choicescript might just be acting loony.


Would you need to check it against length(lists_listname) before finding lists_listname#lists_char?


I imagine that could be the problem. It seems obvious but I’m very confused because there is no problem with any line 21 and I have no idea what line is the problem. Being off by only one (48-49) doesn’t make it easy when I have several lines that use counters and repeating in that one scene alone.
Edit: oops, you are talking about a liable line 21. Just a second.
The whole section of code there is this:

*temp lists_char 0
*temp lists_count 0
*temp lists_string ""
*temp letter
*label alpha
*set lists_char (lists_char + 1)
*set letter lists_listname#lists_char
*if letter = "^"
  *set lists_count (lists_count + 1)
  *if lists_count = lists_index
    *goto beta
    *goto alpha
  *goto alpha

*label beta
*set lists_char (lists_char + 1)
*set letter lists_listname#lists_char
*if (letter = "") or (letter = "^")
  *goto endofthisone
  *set lists_string (lists_string & letter)
  *goto beta
*label endofthisone
*set myvar lists_string

Actually, I just noticed that “freckled” the last item on the list isn’t showing up in the stats screen like the rest.
If I make it so the lists_char is one less before running the label beta, then it stops giving errors but it also stops showing ANY of the list items.


I think that’s the issue: You should check that lists_char isn’t greater than length(lists_listname) before you try to get the letter out.


um… so what would be the right way of writing it? I’m stumped.
Maybe if I swap those two lines you quoted?
Edit: Swapping them does the same thing as making lists_char one less before running beta: no errors but no items either.