Timers, to use or not to use

Weiand
31 Oct 2011, 02:32
I used timers in 2 seperate rooms to make an event happen.

One room, when first enter room, get msg of floor feels weak, starts a timer, then "fall thru" floor to basement. After that, each time entering room, player "fall thru" to the basement.
BUT if leave room before timer finishes, then player "falls" to basement from anywhere.

<timer name="fall">
<interval>10</interval>
<script>
DisableTimer (fall)
msg ("You feel the floor give way as you drop to the basement below.")
MoveObject (player, RD Basement)
msg ("You land on the basement floor feeling very dazed.")
Pause (5)
msg ("You feel as if you can stand and move again.")
</script>
</timer>

I'm guessing either something else is required for if player leaves room before timer finishes, or a timer just won't work here.


The 2nd room is a bit more involved.
Basic concept is enter room, bum sees player, starts to move toward player, grabs player, beats player up & dazes player, then leaves.
IF player shoots bum during that time, kills bum & disables timers.

I've ran into a few problems along the way, most I was able to sort out.

Interact & Look at Bum

<object name="Bum">
<inherit name="container_open" />
<inherit name="male" />
<inherit name="editor_object" />
<look type="script">
if (not GetBoolean(Bum, "dead")) {
msg ("A very dirty bum. Walks very slow with a limp and looks as though he wants to kill you.")
}
else {
if (GetBoolean(Bum, "dead")) {
msg ("A very dirty and dead bum.")
}
}
</look>

<drop type="boolean">false</drop>
<takemsg>No, you don't want to take the bum</takemsg>
<isopen type="boolean">false</isopen>
<openmsg>You check the bums pockets</openmsg>
<displayverbs>Check pockets; Speak to</displayverbs>

<CheckPockets type="script">
if (not GetBoolean(Bum, "dead")) {
msg ("It would be un-wise to check his pockets now")
}
else {
if (GetBoolean(Bum, "dead")) {
HelperOpenObject (Bum)
msg ("You check the bum's pockets")
}
}
</CheckPockets>

<speak type="script">
if (not GetBoolean(Bum, "dead")) {
msg ("I'm going to kill you for being in my house!")
}
else {
if (GetBoolean(Bum, "dead")) {
msg ("The bum is dead and won't be talking back now.")
}
}
</speak>

For Room description:

<object name="RD Kitchen">
<inherit name="editor_room" />
<alias>Kitchen</alias>
<description type="script"><![CDATA[
if (Contains (RD Kitchen,Bum)) {
if (not GetBoolean(Bum, "dead")) {
msg ("What used to be a kitchen. Looks more like a war zone now. The cabinets have been ripped off the walls and broken into bits. The stove is missing the door and the burners are missing. The ice box is missing the door and it has been laid on its back. You think you see someone.<br/>Front Room - West. Small Room - East.")
}
if (Contains (RD Kitchen,Bum)) {
if (GetBoolean(Bum, "dead")) {
msg ("What used to be a kitchen. Looks more like a war zone now. The cabinets have been ripped off the walls and broken into bits. The stove is missing the door and the burners are missing. The ice box is missing the door and it has been laid on its back. You see the dead bum on the floor.<br/>Front Room - West. Small Room - East.")
}
}
}
else {
if (not Contains (RD Kitchen,Bum)) {
msg ("What used to be a kitchen. Looks more like a war zone now. The cabinets have been ripped off the walls and broken into bits. The stove is missing the door and the burners are missing. The ice box is missing the door and it has been laid on its back.<br/>Front Room - West. Small Room - East.")
}
}
]]></description>


If bum has "run away" I get an error while running the game.


For Enter Room:

<usedefaultprefix type="boolean">false</usedefaultprefix>
<prefix>the</prefix>
<enter type="script"><![CDATA[
if (Contains (RD Kitchen,Bum)) {
if (not GetBoolean(Bum, "dead")) {
EnableTimer (bum 1)
}
else {
if (GetBoolean(Bum, "dead")) {
HelperCloseObject (Bum)
}
}
}
else {
if (not Contains (RD Kitchen,Bum)) {
msg ("What used to be a kitchen. Looks more like a war zone now. The cabinets have been ripped off the walls and broken into bits. The stove is missing the door and the burners are missing. The ice box is missing the door and it has been laid on its back.<br/>Front Room - West. Small Room - East.")
}
}
]]></enter>


Timers for "Bum"

<timer name="bum 1">
<interval>5</interval>
<script>
DisableTimer (bum 1)
msg ("The bum notices you and starts to slowly move towards you")
if (not GetBoolean(Bum, "dead")) {
EnableTimer (bum 2)
}
</script>
</timer>


<timer name="bum 2">
<interval>5</interval>
<script>
DisableTimer (bum 2)
msg ("The bum grabs you! You will die if you don't do something quickly!!")
if (not GetBoolean(Bum, "dead")) {
EnableTimer (bum 3)
}
</script>
</timer>


<timer name="bum 3">
<interval>5</interval>
<script>
DisableTimer (bum 3)
msg ("The bum kicks your ass like you've never had it kicked before")
destroy ("Bum")
msg ("You lay on the floor dazed and watch the bum seem to disapear")
Pause (7)
msg ("Able to stand again, you figure the bum is gone for good, but you know you got your ass kicked. You should have shot him.")
</script>
</timer>

MOST of what I wanted to be the end result was obtained. But enough wasn't so that the game just doesn't work correctly.
When player shoots bum, current timer finishes. If player doesn't shoot bum until 3rd timer starts, player gets beat up & Bum "leaves"
If Bum is "dead" when going back into room, all aspects work properly. If Bum has "left" get 2 errors for unknown obj or Vari

Am I missing something or are timers just not the best way to go here?

Alex
01 Nov 2011, 09:36
In your timer script just add an "if", so for the first one check to see if the player is still in the right room. If they are, run the existing falling-through-the-floor script. If they're not, do nothing.