How to make it so each turn brings you closer to death ... except when you enter one room your timer resets.

Laraqua
25 Dec 2017, 08:53

So I want to do something fairly complicated ... I want the Starting Area to be safe and refresh your number of turns available to explore the area. You'd get messages print out every time you enter a room or after a certain number of actions in a room. If you take too long, I want it to print text and basically force you to head back to the starting area where you can then begin again. I figure it has something to do with Turnscript as I don't want it to be a seconds-Timer and probably For Each (i.e. for each room) but I'm not sure where to build it from there. Has anyone got a script available to look at when they've done something similarly?


The Pixie
25 Dec 2017, 12:37

So you need a count attribute on the player that tracks the state. Set up a script for the Starting Area when the player enters the room (lok on the scripts tab of the room) that resets the count:

player.count = 12

The turn script must do two thing; reduce the count and see if the player is dead.

player.count = player.count - 1
if (player.count < 0) {
  msg("You died")
  finish
}

jmnevil54
25 Dec 2017, 13:55

Actually it's not that complicated. You just need to do what The Pixie says, create the turnscript, and then in the enter part script of the room that resets it, you type something like player.count = 20...


mrangel
25 Dec 2017, 14:56

I'd probably put all the script in a turnscript if there's a large number of rooms, rather than creating lots of enter or exit scripts that do the same thing. A bit more complex, but may be easier to maintain if all your code is in one place.

Off the top of my head, a turnscript something like...

if (Contains(Starting area, player)) {
  player.turns_remaining = 20
  player.last_room = player.parent
}
else {
  player.turns_remaining = player.turns_remaining - 1
  if (player.turns_remaining = 0) {
    msg ("Ooops, out of time!")
    finish
  }
  else
    if (player.last_room = player.parent) {
      player.turns_in_room = player.turns_in_room + 1
    }
    else {
      player.last_room = player.parent
      player.turns_in_room = 0
    }
    if ((player.turns_in_room % 5 = 0) or (player.turns_remaining < 5)) {
      msg ("You need to get back to the starting area in "+player.turns_remaining+" turns.")
    }
  }
}

To give the player 20 turns after leaving the starting room, and notify them how many turns they have left when they enter a new room, after spending 5 turns in the same room, or every turn when they have less than 5 left.


Laraqua
26 Dec 2017, 00:01

I kept tinkering with it after posting the question and I figured out how to make the turnscript work in terms of throwing up a message when you're out of the Starting Area too long. Rather than killing them, I'm going to Move Object into a new room so some weird stuff can happen. Thanks for the code to forewarn them that they need to return to the starting area and letting them know how long they have.

    <enter type="script">
      DisableTurnScript (PsychicAssault)
    </enter>
    <onexit type="script">
      EnableTurnScript (PsychicAssault)
    </onexit>````

But now I'm having difficulty getting the turnscript to disable script when they re-enter the Starting Area so the whole thing can refresh.  I tried using just putting in Disable Turn Script in On Enter but that's not working at all.  Once it's started it'll get rid of them even if they spend most of the turns in the Starting Area.  Do I need to make it into an attribute (player.count) or is there a simpler method using the Disable TurnScript command?  I don't know what should be in the brackets after Disable Turn Script so I just put in the name of the script.


Laraqua
26 Dec 2017, 00:08

So now I'm having difficulty getting the turnscript to disable script when they re-enter the Starting Area so the whole thing can refresh. I tried using just putting in Disable Turn Script in On Enter but that's not working at all. Once it's started it'll get rid of them even if they spend most of the turns in the Starting Area. Do I need to make it into an attribute (player.count) or is there a simpler method using the Disable TurnScript command? I don't know what should be in the brackets after Disable Turn Script so I just put in the name of the script.

  <turnscript name="PsychicAssault">
    <script>
      SetTurnTimeout (3) {
        msg ("You feel unsettled, as though you are being watched.")
        SetTurnTimeout (3) {
          msg ("There is a flickering behind your eyes that gives everything a jerky and bizarre sensation to it.")
          SetTurnTimeout (3) {
            msg ("You feel something scratching around inside of your brain.")
            SetTurnTimeout (3) {
            }
            msg ("You are now mind controlled.")
            MoveObject (player, Mind Controlled)
          }
        }
      }
      if (game.pov.parent = Starting Area) {
        DisableTurnScript (PsychicAssault)
      }
    </script>````

DarkLizerd
26 Dec 2017, 02:07

If you can't disable the script...
Then just reset the count each turn they are in the "safe place"...
I assume your SetTurnTimeout is 3,6,8,12...
Instead of a nested approach, you should be able to do this as a flat if statement...

SetTurnTimeout=SetTurnTimeout+1
if(SetTurnTimeout=3) {
msg ("You feel unsettled, as though you are being watched.")
}
if(SetTurnTimeout=6) {
msg ("There is a flickering behind your eyes that gives everything a jerky and bizarre sensation to it.")
}
if(SetTurnTimeout=9) {
msg ("You feel something scratching around inside of your brain.")
}
if(SetTurnTimeout=12) {
msg ("You are now mind controlled.")
MoveObject (player, Mind Controlled)
}

The Pixie
26 Dec 2017, 10:13

To get it to reset every turn the player is in the safe room, add a turn script to the safe room (create it as normal, then move it to the room). That will fire every turn the player is there, and just needs to set the counter back to its original value.

Your first turn script will need going, but because the counter is reset each turn, it does not get any closer to zero.


Laraqua
26 Dec 2017, 10:43

I'm not sure how to reset the count. Thank you for your continued forbearance. It's really making this a lot easier.

Also, I tried the un-nested approach and it threw up an error.


The Pixie
26 Dec 2017, 11:47

The turn script fires every turn. the way you have it set up, it will call SetTurnTimeout every turn, so the event will fire in three turns and in four turns and n five turns, etc.

You need to either use a turn script OR use SetTurnTimeout... and I would advise the turn script, as it is easy to handle once you set it going.

I will slightly modify what I said before; set up two turn scripts, and move one to the safe area. The turn script in the safe area just needs to reset the counter:

player.counter = 0

The other turn script needs to decrease the counter each turn, and then have it trigger events at certain points.

player.counter = player.counter + 1
if (player.counter = 3) {
 msg ("You feel unsettled, as though you are being watched.")
}
if (player.counter = 6) {
  msg ("There is a flickering behind your eyes that gives everything a jerky and bizarre sensation to it.")
}
if (player.counter = 9) {
  msg ("You feel something scratching around inside of your brain.")
}
if (player.counter = 12) {
  msg ("You are now mind controlled.")
  MoveObject (player, Mind Controlled)
}

You would probably need to give the player a "count" attribute and set it to be an integer.

So the turn script will fire every turn, but the counter goes back to zero when the player is in the safe room.


Laraqua
28 Dec 2017, 00:13

Okay, it's working! You guys are incredible! New turnscript issue ... so I want when someone opens a door for a fog to pour out into the surrounding rooms. Technically it's only when they open a door, but really they can't see inside a room without entering it anyway. I'm figuring a general turnscript that starts when they enter a particular room or open a particular door that fires wherever they are ... but stops when they leave the basement. This means I'll need the turnscript to disable once they leave the basement unless I want to put the Turnscript = 0 code in every unaffected room which could be a pain. Plus side is all I need is a message to print as it's fog ... I don't need to reduce health points or anything.


K.V.
28 Dec 2017, 01:06

I think there's a thread somewhere concerning a fire (and smoke filling the building, room by room), but it is hiding from me. (It should be the same concept, though.)

Be right back.


K.V.
28 Dec 2017, 05:27

I couldn't find the thread...

This isn't exactly what you want to happen, but it may help.

If you open the basement door, fog rolls into the house, room by room, depending on how many turns the door has been open.

When you close the door, the fog stops rolling in, but the rooms with fog in them remain foggy.

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="The Fog Rolls In">
    <gameid>5950d7a6-16e7-455b-8202-b018031419f7</gameid>
    <version>1.1</version>
    <firstpublished>2017</firstpublished>
    <foggy type="int">0</foggy>
    <start type="script">
    </start>
    <changedfoggy type="script">
      switch (game.foggy) {
        case (1) {
          kitchen.foggy = true
        }
        case (2) {
          dining room.foggy = true
        }
        case (4) {
          living room.foggy = true
          den.foggy = true
        }
        case (6) {
          bedroom.foggy = true
        }
      }
    </changedfoggy>
  </game>
  <object name="living room">
    <inherit name="editor_room" />
    <foggy type="boolean">false</foggy>
    <changedfoggy type="script"><![CDATA[
      this.description = this.description + "<br/><br/>It's foggy in here."
    ]]></changedfoggy>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="south" to="dining room">
      <inherit name="southdirection" />
    </exit>
    <exit alias="west" to="bedroom">
      <inherit name="westdirection" />
    </exit>
  </object>
  <object name="dining room">
    <inherit name="editor_room" />
    <foggy type="boolean">false</foggy>
    <changedfoggy type="script"><![CDATA[
      this.description = this.description + "<br/><br/>It's foggy in here."
    ]]></changedfoggy>
    <exit alias="north" to="living room">
      <inherit name="northdirection" />
    </exit>
    <exit alias="east" to="kitchen">
      <inherit name="eastdirection" />
    </exit>
    <exit alias="west" to="den">
      <inherit name="westdirection" />
    </exit>
  </object>
  <object name="kitchen">
    <inherit name="editor_room" />
    <foggy type="boolean">false</foggy>
    <changedfoggy type="script"><![CDATA[
      this.description = this.description + "<br/><br/>It's foggy in here."
    ]]></changedfoggy>
    <object name="basement door">
      <inherit name="editor_object" />
      <inherit name="openable" />
      <feature_container />
      <displayverbs type="stringlist">
        <value>Look at</value>
        <value>Open</value>
        <value>Close</value>
        <value>Enter</value>
      </displayverbs>
      <takemsg>It's fixed in place.</takemsg>
      <openscript type="script"><![CDATA[
        msg ("You open it.")
        this.isopen = true
        if (not to_basement.visible) {
          MakeExitVisible (to_basement)
          msg ("<br/>You can go {exit:to_basement}.")
        }
        EnableTurnScript (fog)
        basement_view.visible = true
        kitchen_view.visible = true
      ]]></openscript>
      <closescript type="script">
        msg ("You close it.")
        this.isopen = false
        MakeExitInvisible (to_basement)
        DisableTurnScript (fog)
        basement_view.visible = false
        kitchen_view.visible = false
      </closescript>
      <look>It's {either basement door.isopen=true:open|closed}.</look>
    </object>
    <exit name="to_basement" alias="into the basement" to="basement">
      <visible type="boolean">false</visible>
    </exit>
    <exit alias="west" to="dining room">
      <inherit name="westdirection" />
    </exit>
    <object name="basement_view">
      <inherit name="editor_object" />
      <alias>basement</alias>
      <scenery />
      <visible type="boolean">false</visible>
      <look>You could get a better look if you went inside.</look>
      <displayverbs type="stringlist">
        <value>Look at</value>
      </displayverbs>
    </object>
  </object>
  <object name="bedroom">
    <inherit name="editor_room" />
    <foggy type="boolean">false</foggy>
    <changedfoggy type="script"><![CDATA[
      this.description = this.description + "<br/><br/>It's foggy in here."
    ]]></changedfoggy>
    <beforeenter type="script">
    </beforeenter>
    <onexit type="script">
    </onexit>
    <exit alias="south" to="den">
      <inherit name="southdirection" />
    </exit>
    <exit alias="east" to="living room">
      <inherit name="eastdirection" />
    </exit>
  </object>
  <object name="den">
    <inherit name="editor_room" />
    <foggy type="boolean">false</foggy>
    <changedfoggy type="script"><![CDATA[
      this.description = this.description + "<br/><br/>It's foggy in here."
    ]]></changedfoggy>
    <exit alias="east" to="dining room">
      <inherit name="eastdirection" />
    </exit>
    <exit alias="north" to="bedroom">
      <inherit name="northdirection" />
    </exit>
  </object>
  <object name="basement">
    <inherit name="editor_room" />
    <description>The window is open, and fog is pouring in.</description>
    <beforeenter type="script">
      MoveObjectHere (basement door)
    </beforeenter>
    <onexit type="script">
      MoveObjectHere (basement door)
    </onexit>
    <object name="window">
      <inherit name="editor_object" />
      <inherit name="openable" />
      <feature_container />
      <close />
      <takemsg>It's fixed in place.</takemsg>
      <closescript type="script">
        msg ("You can't.  It's stuck.")
      </closescript>
      <look>It's open and fog is rolling in through it.</look>
      <lookthrough>You see nothing but fog out there.</lookthrough>
    </object>
    <exit alias="out" to="kitchen">
      <inherit name="outdirection" />
    </exit>
    <object name="kitchen_view">
      <inherit name="editor_object" />
      <alias>kitchen</alias>
      <look>You could get a better look if you went inside.</look>
      <displayverbs type="stringlist">
        <value>Look at</value>
      </displayverbs>
      <visible type="boolean">false</visible>
      <scenery />
    </object>
  </object>
  <turnscript name="fog">
    <script>
      game.foggy = game.foggy + 1
    </script>
  </turnscript>
  <command name="enter_cmd">
    <pattern>enter #object#</pattern>
    <script>
      if (not object = basement door) {
        msg ("You can't enter "+object.article+".")
      }
      else {
        if (basement door.isopen) {
          if (game.pov.parent = basement) {
            MoveObject (game.pov, kitchen)
          }
          else {
            MoveObject (game.pov, basement)
          }
        }
        else {
          msg ("It's closed.")
        }
      }
    </script>
  </command>
  <verb>
    <property>lookthrough</property>
    <pattern>look through</pattern>
    <defaultexpression>"You can't look through " + object.article + "."</defaultexpression>
  </verb>
</asl>

Laraqua
28 Dec 2017, 08:27

Oh wow, cool!