hitpoint variable and healing...

Tomsa
02 Aug 2010, 15:05
Suppose I have a numeric variable called HP with the value 25, and make a healing spell that will increment this value 2-8 points each time it is cast, how do I prevent the HP value from exceeding 25?

The same question also applies when discussing destruction spells that would decrement the same value, but should be limited to 0, and not past that point into minus HP (such as -7HP).

Alex
02 Aug 2010, 19:01
Set the variable up as a Status Variable. Then you can run a script each time the value changes - if the value is less than zero, set it to zero, and if it's above the maximum, set it to the maximum.

Tomsa
03 Aug 2010, 11:42
I seem to have solved the problem now, but...the game crashes a lot! Since I have made enough variables and if statements to make my head spin, perhaps it is better for me to post the ASL. It should be perfectly playable by now, if it weren't for all the crashes.

' "The Dice of Death"
' Created with QDK Pro 4.1.2

!include <stdverbs.lib>

define game <The Dice of Death>
asl-version <410>
start <the chamber of deadly games>
game info <Created with QDK Pro 4.1.2>
default fontsize <16>
background <black>
foreground <white>
startscript give <dice d6>
define variable <d6>
type numeric
value <0>
display <!dice>
onchange {
select case <%d6%> {
case <1> {
if flag <guardian's turn> then {
msg <...but nothing happens!>
flag off <Guardian's turn>
choose <dice> } else {
msg <...but nothing happens!>
flag on <Guardian's turn>
do <Guardian > }}
case <2> {
if flag <guardian's turn> then {
if ( %guardian hp% = 25 ) then {
msg <|s00The Guardian heals himself...but his HP is already at maximum.>
flag off <Guardian's turn>
choose <dice> } else {
msg <The Guardian heals one d6.>
inc <guardian hp; $rand(1; 6)$>
flag off <Guardian's turn>
choose <dice> } } else {
if ( %hp% = 25 ) then {
msg <|s00You need no healing - Your HP are maxed!>
flag on <Guardian's turn>
do <Guardian > } else {
msg <You heal one d6.>
inc <hp; $rand(1; 6)$>
flag on <Guardian's turn>
do <Guardian > } }}
case <3> {
if flag <guardian's turn> then {
msg <The Guardian damages you for one d6!>
dec <hp; $rand(1; 6)$>
flag off <Guardian's turn>
choose <dice> } else {
msg <You damage your foe for one d6!>
dec <guardian hp; $rand(1; 6)$>
flag on <Guardian's turn>
do <Guardian > }}
case <4> {
if flag <guardian's turn> then {
msg <The Guardian gains an extra turn! >
do <Guardian > } else {
msg <You gain an extra turn! >
choose <dice> }}
case <5> {
if flag <guardian's turn> then {
msg <"I fart in your general direction!", the Guardian taunts you in an outrageous French accent.>
flag off <guardian's turn>
choose <dice> } else {
msg <"I wave my testicles at your aunts!" you taunt the Guardian by imitating his accent.>
flag on <guardian's turn>
do <Guardian > }}
case <6> {
if flag <guardian's turn> then {
msg <Critical strike! The guardian damages you for one d12.>
dec <hp; $rand(1; 12)$>
flag off <guardian's turn>
choose <dice> } else {
msg <Critical strike! You damage your foe for one d12.>
dec <guardian hp; $rand(1; 12)$>
flag on <Guardian's turn>
do <Guardian > }}
}
}
end define
define variable <HP>
type numeric
value <25>
display <!HP>
onchange {
if ( %hp% <= 0 ) then {
set numeric <hp; 0>
flag off <guardian's turn>
displaytext <lose>
playerlose } else {
if ( %hp% > 25 ) then set numeric <hp; 25> }
}
end define
define variable <Guardian HP>
type numeric
value <25>
display <!Guardian HP>
onchange {
if ( %guardian hp% <= 0 ) then {
set numeric <guardian hp; 0>
flag off <guardian's turn>
displaytext <win>
playerwin } else {
if ( %guardian hp% > 25 ) then set numeric <guardian hp; 25> }
}
end define
end define

define options
debug on
panes on
abbreviations on
end define

define room <the chamber of deadly games>
description <|s09Welcome to Dice of Death!|n|nIn this game you battle against the mysterious Guardian by taking turns using a d6 dice. Each of the six sides of the dice represents an effect, for instance, getting a 3 will damage your opponent for one d6 (1-6 damage) while getting a 5 will result in the taunting of eachother and so forth. When either your or the Guardian's hitpoints reaches 0, the game ends. |n|nStart the game by using the dice d6 in your inventory, which you find in the upper right of the screen.|s00>

define object <dice d6>
take
displaytype <Object>
article <it>
gender <it>
use choose <dice>
end define

define object <Guardian>
look <The black skinned Guardian is dressed in a hooded white robe. A pair of blue eyes are staring intensly at you.>
speak <"When you are ready, use the dice, and we shall do battle!", the Guardian speaks in an ominous voice.>
displaytype <Object>
article <it>
gender <it>
end define

end define

define procedure <Guardian >
msg <|s00The Guardian throws the dice...>
set numeric <d6; $rand(1; 6)$>
end define

define text <win>
You defeated the Guardian. Congratulations - you have won the game!
end define

define text <lose>
You were defeated by the Guardian. The game is over!
end define

define selection <dice>
choice <throw dice> {
msg <You throw the dice...>
set numeric <d6; $rand(1; 6)$>
}
choice <give up> playerlose
end define

Alex
03 Aug 2010, 14:42
Your script is getting stuck in an infinite loop. You are triggering a script whenever "d6" changes, but that script is then calling the "Guardian" procedure, which itself sets the value of "d6", which calls the script again...

Tomsa
03 Aug 2010, 19:48
Yes, I see it quite clearly now...I made Quest vomit by overly complicating things. I will do a hard reset and redo the whole thing, sigh *rolling eyeballs at myself*.