Making an if statement with two conditions

So I want to do an if statement where two requirements have to be met instead of one. Condition on it a particular character is in a particular room so the room is there parent, the second they have to had talked to that character before, so a variable indicating that you have encountered them beofre is true. But not matter how I try to code this the second condition get set instead of seeing if the variable is true to setting it as true or otherwise ignored.
So
If character.parent = room and character.encountered = true { do this}
so far this has not worked and I can not find code for it online that does


if (character.parent = room) {
  if (character.encountered) { // quest understands it to be the same as this: if (character.encountered = true) {
    msg ("BLAH")
  }
  else {
    msg ("Go talk to " + character.name + " first, and then come back here")
  }
}
else {
  msg ("BLAH")
}

// or (just so you can see how they can be combined):

if (character.parent = room and character.encountered) {
  msg ("BLAH")
}
else if (character.parent = room and not character.encountered) {
  msg ("Go talk to " + character.name + " first, and then come back here")
}
else if (not character.parent = room and character.encountered) {
  msg ("BLAH")
}
else {  // or: if else (not character.parent = room and not character.encountered) {
  msg ("BLAH")
}

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

// an example of your 'character':

<object name="character">
  <attr name="encountered" type="boolean">false</attr>
  <attr name="talk" type="script">
    if (not this.encountered) {
      this.encountered = true
      msg ("BLAH")
    }
    else {
      msg ("BLAH")
    }
  </attr>
</object>

// or:

<object name="character">
  <attr name="encountered" type="boolean">false</attr>
  <attr name="talk" type="script">
    firsttime {
      this.encountered = true
      msg ("BLAH")
    }
    otherwise {
      msg ("BLAH")
    }
  </attr>
</object>

you can combine more than just two conditions/checks/expressions:

if (player.alias = "HK" and player.strength = 100 and and player.dead = false and player.weapon = katana) {
}

be aware of the boolean logic involved:

'and' vs 'or' (and/or if 'not' is used or not, lol)

and it's order of operations too:

(A and B) or C
vs
A and (B or C)


https://en.wikipedia.org/wiki/Truth_table

https://en.wikipedia.org/wiki/Boolean_algebra

http://philosophy.lander.edu/logic/symbolic.html (press the 'next page' button at the bottom for more pages to read)

https://www.youtube.com/watch?v=1asxHpewYi8
https://www.youtube.com/watch?v=wRMC-ttjhwM

https://en.wikipedia.org/wiki/Logic_gate
https://www.youtube.com/watch?v=gI-qXk7XojA


So
If character.parent = room and character.encountered = true { do this}

You have pretty much done right there!

if (character.parent = room and character.encountered = true) {
 do this
}

This makes me think there may be some other issue here. I am only guessing, but it could be room does not exist or the character has not got an attribute "encountered". Might be worth trying:

if (character.parent = player.parent and GetBoolean(character, "encountered") {
 do this
}

player.parent is the current room the player is in. The GetBoolean function will return true if the attribute is set, but will return false if it is set to false or does not exist, so is safer when testing an object that might not have the attribute.


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

Support

Forums