Within my game, the player is able to pick up a number of different objects. When they pick up an object the variable ‘holding’ is set to whatever it is they’re holding. E.g. *set holding "knife".
The game also tracks where, in the scene, each object is located. E.g. *set knife "in your hand".
The player needs to be able to drop whatever they are holding if they need to pick up something else. So I have implemented a drop trigger which I am trying to use as follows:
*if (drop_trigger) #Drop the ${holding} on the floor.
*set drop_trigger false
You have dropped the ${holding} on the floor.
*set ${holding} "on the floor"
*set holding "empty"
*goto label
I want to be able to translate that the object has gone from the player’s hand to the floor, as well as emptying the hand for the player to pick up a new object. I believe the problem is with *set ${holding} as it’s coming up as an invalid expression. Is there a better way to go about this?
To use the value of one variable, as the name of the variable you want to alter, you just need to use {} without the $.
*create holding ""
*create knife "on the floor"
*create gun "on the floor"
*label pickup_item
The knife is ${knife}
The gun is ${gun}
What would you like to pick up?
*choice
#Pick up the knife
*set holding "knife"
*set {holding} "in your hand"
*goto drop_item
#Pick up the gun
*set holding "gun"
*set {holding} "in your hand"
*goto drop_item
*label drop_item
The knife is ${knife}
The gun is ${gun}
You are holding the ${holding} . Would you like to drop an item and pick up a new one?
*choice
*if holding != ""
#Drop the ${holding}
*set {holding} "on the floor"
*set holding ""
*goto pickup_item
The curly braces reference a variable{}, while the dollar symbol prints it to the screen $. Sinnie is right on how to use ref in setting a referenced variable.