Which command to use to activate items in an inventory

I’ve been trying to make a basic list or inventory for some time now and I think I have the list right but I just can’t seem to get the right command to set items as true. I keep getting this error every time I try to set an item as true: “Invalid expression at char 14, expected OPERATOR, was: VAR [true]”

Can anyone advise me on what I’m doing wrong?

@Polygon123 Three steps:

  1. Inventory items should be listed in startup.txt, generally starting with a default value of false (not in player’s possession) e.g.

*create sword false
*create axe false

  1. At any point in any ordinary scene file where the player acquires an item, you need to set that item to true, e.g.

The mercenary captain offers you your choice of weapon.
*choice
    #I'll take the sword.
        *set sword true
        You take the sword.
        *finish
    #I'll take the axe.
        *set axe true
        You take the axe.
        *finish

  1. Where you include the inventory code in choicescript_stats.txt for display purposes, you now just need to make sure both ‘sword’ and ‘axe’ are included in there, so either / both will display once set to true at any point in the story, e.g.

*temp inventory ""
*temp comma false
*if (sword)
    *set inventory &"Sword"
    *set comma true
*if (axe)
    *if comma
        *set inventory &", "
    *set inventory &"Axe"
    *set comma true
*if (shield)
    *if comma
        *set inventory &", "
    *set comma true
    *set inventory &"Shield"
*if (helm)
    *if comma
        *set inventory &", "
    *set comma true
    *set inventory &"Helm"
Inventory: ${inventory}.

If this player had accepted the axe, and already had a shield and helm set to true, on the stats page the above would display as:


Inventory: Axe, Shield, Helm.

If you still have any trouble getting it to work as required, post your problem code here using < pre> before and < /pre> after it (but without those spaces) so it displays like the above code (the forum loses your indentation otherwise).

1 Like

Okay but when I try to set an item as true it isn’t read. Does it need to be listed as: *set sword true or *set Inventory “sword” true. I’ve tried both but with the former example the game just glosses over it and doesn’t read the command but if I try the latter I get the error I mentioned before: “Invalid expression at char 14, expected OPERATOR, was: VAR [true]”

@polygon123

*set sword true

The fact that it’s an inventory item is actually irrelevant (except on the Stats page).

If the game appears to be ignoring your use of that command, it must be in the way you’re coding it (e.g. it’s impossible to skip it in the way it’s used in the above example).

I’d recommend posting your code here, including a chunk before and after where you actually use the *set command.

If it makes it easier for you, you can always adopt a naming convention.
e.g. prefixing all the inventory variables:

inventory_sword
inventory_axe
etc…

Then it would be *set inventory_sword true
Hell, even go with *set inventory_has_sword true

Whatever works best for you :slight_smile:

Alright, it’s actually a list of characters that I want to be added during certain key points in the story if the player makes the right choices.

Here is my stat chart:

*create empty true
*create Cedric false
*create Princess false

*create Companions “”
*create comma false

*if (empty)
*set Companions &“You are alone.”
*if (Cedric)
*set Companions &“Cedric”
*set comma true
*if (Princess)
*if comma
*set Companions &","
*set Companions &“Princess”
*set comma true

And here is the problem code:

Their cheers as you depart are incredibly gratifying and Cedric gives you an emphatic salute and a smile, you just made a friend.
*set Companions Cedric true
*set Companions empty false


*create empty true
*create Cedric false
*create Princess false

*create Companions ""
*create comma false

And here is the problem code:

Their cheers as you depart are incredibly gratifying and Cedric gives you an emphatic salute and a smile, you just made a friend.
*set Cedric true
*set empty false

It’s *set Cedric true
Not: *set Companions Cedric true

Okay, I did that and no error came up but my stat screen still isn’t reflecting the change. After the line of code the Companions list still reads: “You are alone” even after I set Cedric true and empty false. I don’t know what else to do unless it’s a problem with my stat chart itself.

You need to add:
${companions}
to the bottom of your stats scene.

Alright I tried that and it still had no effect, Companions still reads “You are alone” after that point in the script.

I’d recommend posting your entire current stats page here, using `

` before it and `

` after your code, so the forum retains your indentation.

Only when we’re absolutely certain there’s nothing wrong with that can we narrow things down to the likely cause.

Did you *set Companion “Cedric” as well? You need to set the variable that changes the text to “Cedric”. Of course, we can’t be certain of the mistake until you post the full code

Oh, I think I see what you’re overlooking, you need to put this bit in your choicescript_stats scene, not your startup scene:


*if (empty)
    *set Companions &"You are alone."
*if (Cedric)
    *set Companions &"Cedric"
    *set comma true
    *if (Princess)
        *if comma
             *set Companions &","
        *set Companions &"Princess"
        *set comma true 

${companions}

Alright I tried it and it’s working just fine now! Thank you so much for your time and patience in helping me solve this, I really appreciate it.

No problem :slight_smile: