Make event conditional on player wearing an item?

Hi,

I want the player to only be able to use/turn on a object if they are wearing a particualr item of clothing, how do I do this? I can't see what I need in the IF options (sure it is there I just don't know what I'm looking for!).

Using online editor.

Thank you.


K.V.

Hello!


Don't set it up as switchable.

Just add two verbs to the object: turn on, and turn off. (You will see the default pop up in the selection box when you've typed in 'turn'.)

image

image


turn on; turn #object# on; switch on; switch #object# on

if (not HasAttribute(device, "switchedon")) {
  device.switchedon = false
}
if (not device.switchedon) {
  if (gloves.worn) {
    msg ("You turn it on.<br/><br/>It does things.")
    SwitchOn (device)
  }
  else {
    msg ("You need to be wearing the gloves to be able to do that.")
  }
}
else {
  msg ("It's already switched on.")
}

turn off; turn #object# off; switch off; switch #object# off

if (not HasAttribute(device, "switchedon")) {
  device.switchedon = false
}
if (gloves.worn) {
  if (device.switchedon) {
    msg ("You switch it off.")
    SwitchOff (device)
  }
  else {
    msg ("It's already off.")
  }
}

IMPORTANT NOTE:
The following bit (which is the first bit in TURN ON and TURN OFF, respectively) is very important, and it MUST be the first bit in each script! (When using the web editor, you cannot set up Attributes. This will set up the Attribute to make sure an error is not thrown.)

if (not HasAttribute(device, "switchedon")) {
  device.switchedon = false
}

Playable sample:

http://play2.textadventures.co.uk/Play.aspx?id=editor/a04446cd-d8b5-4670-b260-9ce46d98eb18%2ftesting-game.aslx


Essentially you need to check tbe "worn" flag of the garment.


Pixie's library creates/adds/uses a 'worn' Boolean Attribute, for determining whether an equipment Object is equipped or not:

for example:

sword.worn = true // sword is eqiupped
sword.worn = false // sword is not equipped

if (sword.worn) { // if (TRUE) // for Boolean Attributes, quest is programmed to understand (and defaulted to use) this shortened form, which is of (is the same as) its long/full form: if (sword.worn = true) { // so, it can cause some confusion for people, unfortunately
  msg ("The sword is equipped") // or: whatever you want to do for this condition
} else { // if (FALSE) // there is no shortened form for when the Boolean Attribute's Value is 'false', but we can just use the 'else' here as Booleans are dualistic (2 states: true/false), but if we didn't use the 'else', we'd have to do either: 'if (not sword.worn) {' or 'if (sword.worn = false) {' or 'if (sword.worn <> true) {'
  msg ("The sword is not equipped") // or: whatever you want to do for this condition
}

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

Support

Forums