Using Either.

I know about using Either in a text command but what about using it for a script. Is this feasible?

Either (player.cold and player.sick=True) {
}

Thanks in advance!

Anonynn.


K.V.
if (HasAttribute(player, "cold") and HasAttribute(player, "sick")) {
  if ((player.cold) and player.sick) {
    msg ("You are cold and sick.")
  }
  else {
    msg ("You're not BOTH cold and sick, but you could be one or the other!<br/><br/>PS<br/>I'm going to check out your game right now, Anonynn!")
  }
}
else {
  msg ("The game creator didn't set those attributes up yet...")
}

K.V.

A little more complex (but not much):

if (HasAttribute(player, "cold") and HasAttribute(player, "sick")) {
  if ((player.cold) and player.sick) {
    msg ("You are cold and sick.")
  }
  else if (player.sick) {
    msg ("You are sick, but not cold.")
  }
  else if (player.cold) {
    msg ("You're cold, but not sick (yet).")
  }
  else {
    msg ("You're neither cold nor sick!<br/><br/>PS<br/>I'm going to check out your game right now, Anonynn!")
  }
}
else {
  msg ("Anonynn didn't set those attributes up yet...")
}

I appreciate it ^_^ The second/complex one is much more helpful!


K.V.

And here it is using switch (just because I'm bored):


if (HasAttribute(player, "cold") and HasAttribute(player, "sick")) {
  switch (player.cold and player.sick) {
    case (true) {
      msg ("You are cold AND sick!<br/>")
    }
    default {
      switch (player.cold) {
        case (true) {
          msg ("You are just cold, but you're working on getting sick too!<br/>")
        }
        default {
          switch (player.sick) {
            case (true) {
              msg ("You're just sick, not cold at all.<br/>")
            }
            case (false) {
              msg ("You're neither cold nor sick.<br/>")
            }
          }
        }
      }
    }
  }
}
else {
  msg ("Anonynn didn't set those attributes up yet...")
}


the concept of 'either' ("either this or that" = 'either or' = 'either') in human (english) language is the 'or' logic:

ht.tp://philosophy.lander.edu/logic/symbolic.html (a link on symbolic logic: connects human language grammer/concept logic and boolean logic/arithmetic, there's page buttons at the bottom, seems like a decent but basic/simple knowledge site, of what few pages I've looked at)

there's also lots of free resource school text books as pdfs or just as inline sites on symbolic logic using this google search:

intro to symbolic logic textbook (scroll down for the pdf and site links, past the amazon/etc commercial/buying links)

if (player.cold or player.sick) { // in full form, it looks like this (assuming you're using Boolean Attributes): if (player.cold = true or player.sick = true) {
  msg ("if the player is cold, you see these messages")
  msg ("if the player is sick, you see these messages")
  msg ("if the player is cold and sick, you see these messages")
} else {
  msg ("if the player is NOT cold and NOT sick, you see this message")
}

now, if you want to do stuff for each condition/state (as K.V. has already given some examples upon):

just do it directly:

if (player.cold and player.sick) { // in full form, it looks like this (assuming you're using Boolean Attributes): if (player.cold = true and player.sick = true) {
  msg ("The player is both cold and sick")
} else if (player.cold) {
  msg ("The player is cold, but is not sick")
} else if (player.sick) {
  msg ("The player is sick, but is not cold")
} else {
  msg ("The player is neither sick nor cold = The player is not sick and is not cold")
}

as, this is much worse:

if (player.cold or player.sick) { // see how this line isn't needed at all, as seen by the code box above this one
  if (player.cold and player.sick) {
    msg ("The player is both cold and sick")
  } else if (player.cold) {
    msg ("The player is cold, but is not sick")
  } else { // else if (player.sick) {
    msg ("The player is sick, but is not cold")
  }
} else {
  msg ("The player is neither sick nor cold = The player is not sick and is not cold")
}

P.S.

I didn't put in checking if scripting for if you have the Attributes or not, so, if you want this, then just use K.V.'s code, as it has these in it. (my code and K.V.'s is exactly the same otherwise, well mostly... K.V. goes into further/additional/extra detail/designs/etc)


I've got a function to make these multiple-case comparisons a bit easier. Takes parameters obj and attrs

attributes = Split (attrs, ";")
result = ""
foreach (a, attributes) {
  if (HasBoolean (obj, a)) {
    if (GetBoolean (obj, a)) {
      result = result + a
    }
  }
}
return result

Then if I want to check multiple states, I can use something like:

switch (GetMultipleBooleans (player, "cold;sick")) {
  case ("cold") {
    msg ("You are cold!")
  }
  case ("sick") {
    msg ("You are sick")
  }
  case ("coldsick") {
    msg ("You are cold and sick. Sympathy!")
  }
  default {
    msg ("You're fine, dude")
  }
}

I find something like that makes the script easier to read :)


K.V.

That's pretty awesome, mrangel!


KV I actually use a more complex version, but figured it's too big to post here (and contains code I'm embarrassed about). So I can maybe do things like

msg ("You march into the doctor's office and demand attention")
switch (GetMultipleAttributes (player, "flu;poison>3;syphillis;health<20")) {
  case ("health") {
    msg ("'Been in a fight?' the doctor asks, 'Buy a potion from the receptionist and stop bothering me'")
  }
  case ("poison") {
    msg ("The doctor gives you an antidote and sends you on your way")
  }
  case ("poisonhealth") {
    msg ("'Get a healing potion and an antidote from the receptionist!' the doctor says")
  }
  case ("") {
    msg ("The doctor kicks you out because there's nothing wrong with you")
  }
  default {
    msg ("The doctor asks you to take your clothes off so he can examine you")
  }
}

(script checks for attributes that are boolean true; are a non-empty string; are a non-zero integer; are a non-empty list; or exist and aren't any of those types. Strings and integers can also be compared against a particular value)


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

Support

Forums