Room Entrance Requirements (Text Adventure)

Is there a way to set some sort of requirement-to-be-met to enter a room? I've looked through the script options and can't see any obvious choices.

Something along the lines of 'You can't enter this room unless you have this item' etc.

Thanks!


Hi Yuno, you can do this through the exit:room object, the first tab of which is exit.
This is the room before the one for which you want to set the condition to enter.
Towards the bottom of the page you will see a checkbox, Run a script (instead of moving the player automatically.

Tick the box, add an If statement, and your conditions.

if (not Got(rabbit)) {
  msg ("You cannot pass")
}
else {
  MoveObject (player, field)
}

Hope that helps


This did help, thank you. On the same note, I'm guessing it is possible to make a room dependent on having two objects, yes?


Yes, you might have to press the code view for that, then put an 'and' condition, then, not Got(x). You could even do an 'or' condition. Just watch the spaces between words and capital 'G' for 'Got', and the number of brackets around the condition ().


'and' requires both conditions being true, for it to be TRUE
'or' requires at least one condition being true, for it to be TRUE

'and' logic:
true and true = TRUE
true and false = FALSE
false and true = FALSE
false and false = FALSE

'or' logic:
true or true = TRUE
true or false = TRUE
false or true = TRUE
false or false = FALSE


I don't know the GUI/Editor that well and maybe it does have script options for doing multiple conditions... but there's always the 'cheat' way, via using the '[EXPRESSION]' script option, which allows you to GUI/Editor-code-script in whatever you want. The other way, is as already mentioned by Doctor Agon, by going into the code (either: an individual code-part: Script Attribute or Verb, the GUI/Editor's Full Game Code View, and/or directly into the code via right clicking on your game file itself and choosing a text editor software, notepad, wordpad, notepad++, Apple: text editor, etc, to open it up.

examples:

run as script -> add new script -> 'scripts' section/category -> 'if' Script -> (see below)

if [EXPRESSION] Got (sword) and Got (shield) // or: if [EXPRESSION] sword.parent = player and shield.parent = player
-> then, -> add new script -> 'variables' section/category -> 'set a variable or Attribute' Script -> set variable player.parent = [EXPRESSION] room_99 // or: 'scripts' section/category -> 'call function' Script -> Function's Name: MoveObject, Function's (Add) Parameters: player, room_99
else,
-> add new script -> 'output' section/category -> 'print a message' Script -> print [MESSAGE] You can't go to room_99 without a sword and shield

// --------------------------------------

<object name="sword">
  <inherit name="equipment_type" />
  <attr name="parent" type="object">room</attr>
</object>
<object name="shield">
  <inherit name="equipment_type" />
  <attr name="parent" type="object">room</attr>  
</object>
<object name="player">
  <attr name="parent" type="object">room</attr>
</object>
<object name="room">
</object>
<object name="room_99">
</object>
<type name="equipment_type">
  <attr name="displayverbs" type="listextend">equip</attr>
  <attr name="equip" type="script">
    if (not this.parent = player) {
      this.parent = player
      list remove (this.displayverbs, "equip")
      list add (this.inventoryverbs, "unequip")
    }
  </attr>
  <attr name="unequip" type="script">
    if (this.parent = player) {
      this.parent = null
      list remove (this.inventoryverbs, "unequip")
      list add (this.displayverbs, "equip")
    }
  </attr>
</type>
<verb>
  <property>equip</property>
  <pattern>equip</pattern>
  <defaultexpression>You can't equip that!</defaultexpression>
</verb>
<verb>
  <property>unequip</property>
  <pattern>unequip</pattern>
  <defaultexpression>You can't unequip that!</defaultexpression>
</verb>

// -------------------------------

// (WHERE-EVER: Verb/Script Attribute, Command, Function, Turnscript, Timer, Object Type, etc etc etc) scripting:

if (Got (sword) and Got (shield)) {
  MoveObject (player, room_99) // or: player.parent = room_99
} else {
  msg ("You can't go to room_99 without a sword and shield")
}

// or:

if (sword.parent = player and shield.parent = player) {
  player.parent = room_99  // or: MoveObject (player, room_99)
} else {
  msg ("You can't go to room_99 without a sword and shield")
}

// or: 

if (Contains (player, sword) and Contains (player, shield)) {
  player.parent = room_99 // or: MoveObject (player, room_99)
} else {
  msg ("You can't go to room_99 without a sword and shield")
}

ask if you got any questions or need help with anything


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums