Default Health
Spieltgeist
27 Jul 2013, 18:40Hi all,
I'm working on my first game and I got a good portion of the program figured out. Marvelous by the way, but I hit a snag when it comes to the health.
What I'm trying to do is give the player a warning when their health reaches a certain point (< 10) but I can't figure out how to reference the default code for player health. I've see a lot of work arounds for this by adding health as an attribute for the player, however doing so pretty much invalidates every easy to use script feature involving the default health which would be a problem for me since I'll need to be changing health a lot during the game.
Does anyone know how to reference the default health value that the game uses? Is it even possible?
I'm working on my first game and I got a good portion of the program figured out. Marvelous by the way, but I hit a snag when it comes to the health.
What I'm trying to do is give the player a warning when their health reaches a certain point (< 10) but I can't figure out how to reference the default code for player health. I've see a lot of work arounds for this by adding health as an attribute for the player, however doing so pretty much invalidates every easy to use script feature involving the default health which would be a problem for me since I'll need to be changing health a lot during the game.
Does anyone know how to reference the default health value that the game uses? Is it even possible?

jaynabonne
27 Jul 2013, 19:04Here is a little hack-ish type thing that should work (assuming I understand what you want to do). You can try this by copying it to a new game script - replace the boilerplate that Quest creates.
The "changedhealth" script is called whenever the health attribute changes. Unfortunately, that script is set inline down in the core in InitPOV. But you can assign scripts all you want. In this case, in the game start script, the changedhealth script is saved elsewhere in the player object, and a new one is set. Then in this new one, it invokes the old one (to keep the old behavior) and then does the less-than-10 check. You could skip the "saving the old" code if you wish to just incorporate the existing healthchanged code into your own. That is here:
Let me know if any of this makes sense or if you need further help.
<!--Saved by Quest 5.4.4873.16527-->
<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="healthtest">
<gameid>17c62dbe-f8bf-427c-9382-e18eceaf95ba</gameid>
<version>1.0</version>
<showhealth />
<firstpublished>2013</firstpublished>
<start type="script">
game.pov.origchangedhealth = game.pov.changedhealth
game.pov.changedhealth = game.pov.mychangedhealth
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<mychangedhealth type="script"><![CDATA[
do (this, "origchangedhealth")
if (this.health <= 10) {
msg ("You're on death's door. Better heal yourself soon!")
}
]]></mychangedhealth>
</object>
</object>
<command name="pain">
<pattern>pain</pattern>
<script>
player.health = game.pov.health - 5
msg("Your health is now " + game.pov.health)
</script>
</command>
</asl>
The "changedhealth" script is called whenever the health attribute changes. Unfortunately, that script is set inline down in the core in InitPOV. But you can assign scripts all you want. In this case, in the game start script, the changedhealth script is saved elsewhere in the player object, and a new one is set. Then in this new one, it invokes the old one (to keep the old behavior) and then does the less-than-10 check. You could skip the "saving the old" code if you wish to just incorporate the existing healthchanged code into your own. That is here:
if (this.health > 100) {
this.health = 100
}
else if (this.health <= 0) {
this.health = 0
if (HasScript(game, "onhealthzero")) {
do (game, "onhealthzero")
}
}
Let me know if any of this makes sense or if you need further help.
Spieltgeist
27 Jul 2013, 19:46Oho!
I plugged in the code and set up a few test instances. This definitely seems to have done the trick. Thanks a lot mate!
I plugged in the code and set up a few test instances. This definitely seems to have done the trick. Thanks a lot mate!