Print message based on range of integer attribute?

What is the syntax for printing a message for an attribute that falls between a range of numbers?

My plan is to print a message when the health of the opponent falls inside a certain range. I also only want that message to print one time. Example: Attack 'fanged rat' --> "You strike the rat with your cup of pudding (?) and it winces in pain." That attack does 13 damage and the health of the rat falls from 100 to 87. After the attack, I would like to print a message like "The rat looks angered and ready to nibble your bum." I'd like it to print only once in the range between 80-90 though. Then, when the health falls in between 50-60 (the next range), print another message like "The Fanged Rat seems a bit weaker, yet still a dangerous foe."

Does that make sense?

within a range: you use the 'and' logic operator (and make sure you got your greater-thans/lesser-thans, correct!), an example:

// within 0-100:
if (player.strength >= 0 and player.strength <= 100) { /* scripting */ }

outisde of a range: you use the 'or' logic operator (and make sure you got your greater-thans/lesser-thans, correct!), an example:

// outside of 0-100:
if (player.strength < 0 or player.strength > 100) { /* scripting */ }

a way to help with understanding the use of 'and' vs 'or', is to use a VENN diagram: (math-graphing example: unions=and, intersections=or) (circuitry/computer architecture - more advanced programming)

a pretty good link for this stuff


if (Fanged Rat.Health >= 80 and Fanged Rat.Health <= 90) { /* scripting */ }

just edited my last post, added in a link for VENN diagrams on helping with the logic of 'and' vs 'or' logic operators/operations

yes, that is correct, for WITHIN 80-90 (inclusive: including 80 and 90)

you would do something like this:

// obviously (hopefully), this example function is horribly incomplete/wrong/bad (infinite loop) -- it needs much more code lines, but it's just a simple-quick-brief example:

<function name="combat_example">
  if (Fanged >= 80 and Fanged <= 90) {
    firsttime {
      msg ("blah first time")
    } otherwise {
      msg ("blah otherwise")

Cool. Thanks. I'll give it a try and let you know.

you can make the code more efficient, with something like this (guessing on your combat design):

the series of 'ifs/else ifs/else' does the same effect as using the 'and' operator, and is more efficient (less operations)

if (Fanged >= 100) {
  msg ("100-positive_infinite")
} else if (Fanged >= 90) {
  msg ("90-99")
} else if (Fanged >= 80) {
  msg ("80-89")
} else if (Fanged >= 70) {
  msg ("70-79")
} else if (Fanged >= 60) {
  msg ("60-69")
} else if (Fanged >= 50) {
  msg ("50-59")
} else if (Fanged >= 40) {
  msg ("40-49")
} else if (Fanged >= 30) {
  msg ("30-39")
} else if (Fanged >= 20) {
  msg ("20-29")
} else if (Fanged >= 10) {
  msg ("10-19")
} else {
  msg ("negative_infinite-9")

It can also be done with the text processor as discussed in this thread:


When the player leaves the room (runs away), here is the script I have in the After Leaving Room section. I want the rat health to reset to 100.

Fanged Rat.Health = Fanged Rat.Health = 100

But, when the player leaves the room, I get the following error message.

Error running script: Error compiling expression 'Fanged Rat.Health >= 80 and Fanged Rat.Health <= 90': CompareElement: Operation 'GreaterThanOrEqual' is not defined for types 'Boolean' and 'Int32'

Too many "="'s...
what you are accidently saying is...
Fanged Rat.Health = False...
you are assigning a Boolean to a number...
(hmm... just like the error says...)
all you need is:
Fanged Rat.Health = 100

Doh. Will try. Thanks!

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