Using objects to change variables

KidPresentable
26 May 2011, 05:19
I'm trying to find a way to make it so using an object both changes a variable, and changes a property of the object.

Say I had a box of ten pills. I would like using one pill to increase "Health" by 10 or 10% (is changing values by percentages possible?), and decrease the number of pills in the box by one. When the number of pills hits zero I would like the "Box" object to disappear.

I'd also like to have an object that acts on "Health" in the opposite way. Say, a bottle with ten drops of poison in it. Use one drop and health decreases by 10 or 10%.

Ideally I would like a different message to print depending on whether "Health" changes positively or negatively, or possibly a warning message if, say, "Health" drops below 50.

If it were at all possible, I'd love for the description of "Health" to change depending on its value - maybe 90 is "Hale and Hearty" and 30 is "Sickly."

Is any of this doable?

RedTulip
26 May 2011, 11:18
I made an .asl that, maybe, does what you want.

KidPresentable
26 May 2011, 22:40
Awesome, thanks!

KidPresentable
28 May 2011, 04:47
Your example works well, but I have no idea how to replicate that in my own game. What tree menu options should I be going through? I know it's in Game/Advanced and then "Select Case," but after that I get stuck in an endless loop of "select case" windows, with no apparent way to enter the code you gave me. Could you possibly walk me through it step by step?

RedTulip
01 Jun 2011, 12:59
Ok, first....

Click the Game link in the tree on the left, then edit the script that runs when the game starts.

Add a script, if it hasn't been added already, and collapse the 'Variables' link.

Click the 'Set a numeric variable' script to change or make a variable.

Type 'poison' as the name of the variable, and 10 as the amount.

Click the 'Add more >' button to add another script. Another 'Set a numeric variable' script should appear. This time, the name should be 'pills' and the amount the same, 10.

Add another script, another 'Set a numeric variable' script. The name should be 'int_health'. Amount should be 100.

Click OK.

Click the Advanced tab.

Choose the 'After each turn' script command.

Edit the script.

Add a select case script.

As the select case, type '%int_health%' or click the '%' (numeric variable) button and type 'int_health' on the name of the variable box and clicking OK.

Add a case.

As the case, type '0; 10; 20; 30; 40'. Click OK.

The script editor should pop open. Click OK, we'd change the script later on.

Add another script, this time a 'Case else' script.

The script editor should open, click OK. Editing that later...

Click OK to close the script editor and save.

Collapse the Game link and click Status Variables.

Add a variable called 'health'.

Choose the 'String' option instead of the 'Numeric' option.

As the initial value, type 'Hale and Hearty'.

As the display, type 'Health: !'. '!' would be the value.

Click OK.

Click the Game link, again. Click the Advanced tab and edit the 'After each turn' script, again.

Edit the script of the first case (the '0; 10; 20; 30; 40' case).

Collapse the Variables link, if it's not, already, and click 'Set a string variable'.

Type 'health' as the name. Set 'Sickly' as the contents.

Edit the Else case script.

Choose the 'Set a string variable' script, if you haven't already, and type 'health' as the name. Instead of 'Sickly' being the contents, type 'Healthy and Hearty'.

Click OK.

Click OK.

Now that all of those are done, add a room (maybe a bathroom), if you haven't already, where the poison and pills should be in.

Add an object called 'poison'. Set the prefix, maybe, to 'a bottle of'. In the look verb, you could type 'A bottle of poison, or so it says.'.

Click the inventory tab.

Click the 'Edit 'Use' details...' button below.

Under the 'Other' category, click 'Use poison (on its own)'. Edit the script.

Add a Select case script. As the select case, type '%poison%'.

Add a case. Set the case as '10; 9; 8; 7; 6; 5; 4; 3; 2; 1'.

Click OK.

Choose the 'Print a Message' script.

As the message, type 'You sip a drop of poison.'.

Add another script that decrements a numeric variable. The variable should be the poison variable (click the black arrow on the side of the 'Numeric variable name' text box, choose the poison variable).

The decrement amount should be 1.

Add another script that decrements another numeric variable. The variable should be the int_health variable, this time.

Decrement amount should be 10. Click OK.

Click OK.

Click Close.

Add another object in the same room. Call this one... pills.

Set the prefix as 'a box of'.

Set the look message as 'A box of pills, the tape says.'.

Edit the 'Use' details for the pills.

Edit the script of 'Use pills (on its own)'.

Add a select case. The select case should be '%pills%'.

Add a case. The case should be '10; 9; 8; 7; 6; 5; 4; 3; 2; 1'.

The script should print a message saying "You pop a pill into your mouth.", decrement the 'pills' numeric variable by 1, and increment the 'int_health' by 10.

Click OK.

Click OK.

Click Close.

You should be done. Hope it works :)