Combination lock?

Hi,

I'm fairly new to this software and I can't seem to find an answer on how to do that a combination lock. I'm designing a simple escape room type of game for my students to play in.

I can make a lock and a key to open it, but I'm not sure which script to use in order to make a lock that requires the player to type in a combination (ex: 753).

Thank you for any help you can give.


When the player looks at the keypad...
msg("It looks like you need to enter a number.")
get input {
keyed=ToInt(result)
if(keyed=doorcode) {
msg("The green light comes on and the door opens.")
} else {
msg("The red light comes on and the keypad emits a bad sounding beep.")
}


there's only two ways of getting typed-in input:

  1. the 'get input' Script/Function: http://docs.textadventures.co.uk/quest/scripts/get_input.html
  2. the 'Command' Element: http://docs.textadventures.co.uk/quest/elements/command.html

oh, nice. Thanks I was putting in the get input but not the keyed part. Sweet!


you can just use the built-in 'result' Variable VARIABLE too (sometimes it's good to create another Variable Variable or usually you need an Attribute VARIABLE, and sometimes it's better to just use the 'result' Variable VARIABLE).

'result' is a built-in Variable VARIABLE ('get input' and 'show menu/ShowMenu' and 'ask/Ask' all store your input automatically/hidden-from-you into the built-in 'result' Variable VARIABLE)

your/custom 'keyed' Variable VARIABLE is no different than the built-in 'result' Variable VARIABLE (so why re-store your input into another Variable VARIABLE: 'keyed', when your input is already stored in the Variable VARIABLE: 'result', ??? Unless you've got a reason for needing to store it into your own/custom Variable VARIABLE, just use the 'result' Variable VARIABLE)

// When the player looks at the keypad:

msg ("It looks like you need to enter a number.")
get input {
  if (ToInt (result) = NAME_OF_OBJECT.NAME_OF_DOOR_CODE_INTEGER_ATTRIBUTE) {
    msg("The green light comes on and the door opens.")
  } else {
    msg("The red light comes on and the keypad emits a bad sounding beep.")
  }
}

// or:

msg ("It looks like you need to enter a number.")
get input {
  if (result = NAME_OF_OBJECT.NAME_OF_DOOR_CODE_STRING_ATTRIBUTE) {
    msg("The green light comes on and the door opens.")
  } else {
    msg("The red light comes on and the keypad emits a bad sounding beep.")
  }
}

Is it possible for anyone to explain this a bit more please? I am incredibly confused about how to make this work.


Have you seen this tutorial:
http://docs.textadventures.co.uk/quest/guides/unlockdoor.html


Ah, thank you. I hadn't seen it. I'll go and educate myself!


It doesn't seem to like my result="2306"

use keypad
Enter the security code please.
Error running script: Error compiling expression 'result="2306"': Unknown object or variable 'result'

Do you know why that might be?


I'd missed a step. I'd missed "get input, then run script" and moved straight onto the if statement.


Hi, followed the Unlockdoor tutorial. Keep getting the following message after you type in the combination to unlock the door.

Error running script: Error compiling expression 'result=game.code': CompareElement: Operation
'Equal' is not defined for types 'String' and 'Int32'

I followed the tutorial step-by-step.


you have a mismatch of data types:

'string' vs 'integer'

it looks like your 'game.code' is set as an Integer Attribute, and when you use 'get input', the inputted Value by you, is always a String Value, thus:

result (String Value) = game.code (Integer Value) ---> ERROR

so, you have to change one to match the other:

ToInt (result) = game.code // int = int

or

result = ToString (game.code) // string = string

or

go back and change your 'game' Game Settings Object's 'code' Integer Attribute into a String Attribute:

'game' Game Settings Object -> 'Attributes' Tab -> Attributes (the box at the bottom I think, NOT the statusattributes box!) -> (scroll through the attributes until you find your 'code' attribute) -> change it's Attribute Type from 'int' to 'string' (see below for how the Attribute should look)

(Object Name: game)
Attribute Name: code
Attribute Type: string (change it from int to string)
Attribute Value: (keep the same Value/number as you had before)

result = game.code // NO error // string = string

P.S.

here's a quick reference guide on Data/VARIABLE/VALUE Types:


anything encased in double quotes, IS a String Value

anything NOT encased in double quotes and IS a non-decimal number (-1000000, -3, 0, 7, 12847), IS an Integer (int) Value

anything NOT encased in double quotes and IS a decimal number (4.67754325, 1.2, 0.000001, -9.9, etc), IS a Double Value

anything NOT encased in double quotes and NOT numerical (not integer nor double) and NOT a special/reserved Value (such as 'true' and 'false', which are reserved for a Boolean's Values), IS an Object reference/pointer Value

'true' and 'false' with NO double quotes, ARE a Boolean's Values

special/reserved Values:

'true', 'false', 'this', and probably more (like all the built-in terms, VARIABLES, Elements, etc)... but can't think of them,


game.string_attribute = "4" // the '4' is a String Value, because of the double quotes // NO error

game.integer_attribute = 4 // the '4' is an Integer (int) Value, because there's no double quotes and it is a (non-decimal) number // NO error


game.string_attribute = 4 // ERROR! You can't store an Integer Value into a String Attribute
game.integer_attribute = "4" // ERROR! You can't store a String Value into an Integer (int) Attribute


game.greeting_string_attribute = "Hi, welcome to my game, I hope you enjoy it!" // String Attribute storing a String Value // NO error


<object name="sword">
</object>
game.right_hand_object_attribute = sword // the 'sword' is an Object reference/pointer Value, because it does NOT have double quotes, nor is it numeric (not an integer nor a double:float/floating point/decimal number), nor is it a special value such as 'true' and 'false', which are reserved for a Boolean's Values // NO error

game.right_hand_object_attribute = "sword" // ERROR! You can't store a String Value into an Object Attribute


<object name="sword">
</object>
game.right_hand_string_attribute = sword // ERROR! You can't store an Object Value into a String Attribute

<object name="sword">
</object>

game.right_hand_object_attribute = sword // NO error, as you DO have an existing 'sword' Object

vs

game.right_hand_object_attribute = sword // ERROR! You need to actually have an existing 'sword' Object! you do NOT have an existing 'sword' Object

Hi. I don't think the "change your 'game' Game Settings Object's 'code' Integer Attribute into a String Attribute", will work. Following the tutorial for the combination lock and the random number section located in that tutorial, you are setting the script to run in the start script. Cannot see a specific attribute that says 'code' in the 'game' object itself, or the 'keypad' object. But doing either of your other suggestions does seem to work. The tutorial, then, might need updating.


hmm.. well if you're using a library (Pixie's), then that 'code' Integer Attribute will be in his library...

open up Pixie's library file in code:

right click on the file itself and choose to open it with some text editor software: notepad, wordpad, notepad++, Apple: texteditor, etc... and then find the 'game' Game Settings Object, and look for a 'code' Attribute:

<game name="PIXIE_LIBRARY">
  // blah Attributes
  <attr name="code" type="int">0</attr> // or: <code type="int">0</code> // you'd change the: type="int", to: type="string"
  // blah Attributes
</game>

though, Pixie has his library set up to use the 'game.code' as an Integer Attribute, so don't change it, as then you'd have to change the rest of Pixie's library to handle the 'game.code' now being a String Attribute


oops... helps to fully read your post, laughs...

Pixie uses scripting (via the 'game' Game Settings Object's 'start' Script) to create the Attributes, they're not created via the pre-game-initialization (you manually set them in code/GUI/Editor, so they're already created before the game is built-up: aka initialized) means I was was talking about at the top of my post. So, pretending you'd want to do this, you'd need to change his scripting in his 'game.start' Script Attribute, something like this:

(the 'game.start' Script Attribute is the first thing that is executed/done/activated after the game is initialized, so Pixie's Attributes are created before you are able to play the game)

<library>
  <game name="PIXIE_LIBRARY">
    <attr name="start" type="script"> // or: <start type="script">
      // blah scripting
      // one of these (the zero can be as whatever number, don't know what Pixie put for his library):
      // set (game, "code", 0)
      // or
      // set (this, "code", 0)
      // or
      // game.code = 0
      // or
      // this.code = 0
      // blah scripting
    </attr> // or: </start>
  </game>
</library>

actually... Pixie may have a Function call inside of the 'game.start'... so you'll ahve to find that Function... meh... I should download Pixie's library to be exact with trying to help you understand how to do this stuff... but I am too lazy, lol.


I have had a proper look at the tutorial, and realised it had a bug and needed some updating (it does not mention the Features tab or text processor, so presumably pre-dates them). It is now updated.

The difference is that the start script on the game object should be:

game.code = "" + GetRandomInt(1000, 9999)

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

Support

Forums