Two counters in a if statement

So what I'm trying to do is run and if statement for my counters. I have 2 counters I need initiated in the statement example:

Lets say I have Counter Stamina and Counter Health

I want to do something like,

If Health = 100

then ( Message Here)

else If Health is < 100
Then (different message)

else if Stamina < 20
then (different message)

So what I want to happen when it goes to the next page, if stamina is above 20 and health = 100, then play first message,

if stamina is above 20 and health is < 100, then play second message

If stamina is below 20 automatically play third message without health being a factor.

when I code it it will play 2 messages at one time if stamina is below 20.

any thoughts?


If I understand you correctly, try this...

If Stamina < 20 then message 3
else
if Health = 100 then message 1
else
message 2

Hope this helps.


Yes that worked perfectly!! Thank you!


If you need help understanding why - if the player had stamina 10 and health 100 then Health = 100 and stamina < 20 are both true.

In a if / else if / else if chain, when multiple conditions are true, it picks the first true one. So you decide which of those blocks you want to run if both are true, and then put that one first.


Ahhh, that makes a lot of sense. Thanks for helping me with the description. That will help me further on in the game


'DEFINITION' logic:

true -> TRUE
false -> FALSE


Unary (1 operand) Operator:

'NEGATION' ('NOT') Logic:

not true -> FALSE
not false -> TRUE


Binary (2 operands) Operators:

'AND' logic:

true and true -> TRUE
true and false -> FALSE
false and true -> FALSE
false and false -> FALSE

'OR' logic:

true or true -> TRUE
true or false -> TRUE
false or true -> TRUE
false or false -> FALSE


some examples with working with more than 2 operands (only showing 3 operands though for this example)

// C++ operator priority ranking and its association for an example (they got more operators, but you can ignore them, as quest probably doesn't have them): https://en.cppreference.com/w/cpp/language/operator_precedence

// Java operator priority ranking and its association for an example (they got more operators, but you can ignore them, as quest probably doesn't have them): https://introcs.cs.princeton.edu/java/11precedence/

// without any parenthesis, it's default priority's association is: left to right

// just like with math, the parenthesis have a higher priority than its default (lowest) priority of 'left to right'

(true and false) and true --> FALSE
true and (false and true) --> FALSE

false and (false and true) -> FALSE

(true or false) and true -> TRUE
true or (false and true) -> TRUE

false or (false and true) -> FALSE


examples of the boolean logic above and using 'if/if-else/else' scripting examples too:

// preparation stuff for my examples:

boolean_stringlist_variable = split ("true;false", ";")

randomly_selected_boolean_variable_1 = StringListItem (boolean_stringlist_variable, GetRandomInt (0, ListCount (boolean_stringlist_variable) - 1))
// randomly_selected_boolean_variable_1 = [randomly selected: true/false]

randomly_selected_boolean_variable_2 = StringListItem (boolean_stringlist_variable, GetRandomInt (0, ListCount (boolean_stringlist_variable) - 1))
// randomly_selected_boolean_variable_2 = [randomly selected: true/false]

create ("npc")

npc.currency_integer_attribute = 0

------------------

// 'AND' logic:

clean_room_boolean_variable = randomly_selected_boolean_variable_1

msg ("Clean Room Boolean Variable: " + clean_room_boolean_variable)

mow_lawn_boolean_variable = randomly_selected_boolean_variable_2

msg ("Mow Lawn Boolean Variable: " + clean_room_boolean_variable)

if (clean_room_boolean_variable and mow_lawn_boolean_variable) {
  msg ("You cleaned your room and mowed the lawn! You get $5 for completing both chores!")
  npc.currency = npc.currency + 5
} else if (clean_room_boolean_variable) {
  msg ("You cleaned your room, but didn't mow the lawn. You only get $5 when you've done BOTH chores.")
} else if (mow_lawn_boolean_variable) {
  msg ("You mowed the lawn, but didn't clean your room. You only get $5 when you've done BOTH chores.")
} else {
  msg ("You didn't mow the lawn, nor did you clean your room. You only get $5 when you've done BOTH chores.")
]

---------------

// ''OR' logic:

clean_room_boolean_variable = randomly_selected_boolean_variable_1

msg ("Clean Room Boolean Variable: " + clean_room_boolean_variable)

mow_lawn_boolean_variable = randomly_selected_boolean_variable_2

msg ("Mow Lawn Boolean Variable: " + clean_room_boolean_variable)

if (clean_room_boolean_variable or mow_lawn_boolean_variable) {

  // the first/left-most condition (clean_room_boolean_variable) is checked first, and since this is the 'or' logic, if it's true, then it doesn't need to check the 2nd condition

  msg ("You either cleaned your room or you mowed the lawn! You get $5 for completing either one of the chores or for doing both chores!")

  npc.currency = npc.currency + 5

  if (clean_room_boolean_variable) {

    msg ("You cleaned your room")

    if (lawn_mowed_boolean_variable) {
      msg ("You also mowed the lawn.")
    } else {
      msg ("But, you didn't mow the lawn")
    }

  } else if (lawn_mowed_boolean_variable) {
    msg ("You mowed the lawn, but didn't clean your room")
  }

}  else {

  msg ("You didn't mow the lawn, nor did you clean your room. You only get $5 when you've done BOTH chores.")

]

-------------------

// 'NEGATION' logic using the AND' logic from a bit above:

clean_room_boolean_variable = randomly_selected_boolean_variable_1

msg ("Clean Room Boolean Variable: " + clean_room_boolean_variable)

mow_lawn_boolean_variable = randomly_selected_boolean_variable_2

msg ("Mow Lawn Boolean Variable: " + clean_room_boolean_variable)

if (not clean_room_boolean_variable and not mow_lawn_boolean_variable) {
  msg ("You didn't mow the lawn, nor did you clean your room. You only get $5 when you've done BOTH chores.")
} else if (not clean_room_boolean_variable) {
  msg ("You didn't clean your room.")
} else if (not mow_lawn_boolean_variable) {
  msg ("You didn't mow the lawn.")
} else {
  msg ("You cleaned your room and mowed the lawn! You get $5 for completing both chores!")
  npc.currency = npc.currency + 5
]

the different structures/patterns/designs of the 'if' script and its logic:

if (CONDTION/S) {
  // scripting
}

--------

if (CONDTION/S) {
  // scripting
} else {
  // scripting
}

--------

if (CONDTION/S) {
  // scripting
} else if (CONDITION/S) {
  // scripting
}
// optional: more 'else-ifs'

--------------

if (CONDTION/S) {
  // scripting
} else if (CONDITION/S) {
  // scripting
}
// optional: more 'else-ifs'
else {
  // scripting
}

--------

if (CONDTION and CONDITION) {
  // scripting
}

// or the same logic:

if (CONDITION) {
  if (CONDITION) {
    // scripting
  }
}

-----------

if (CONDITION) {
  // scripting
} else {
  if (CONDITION) {
    // scripting
  } else {
    // scripting
  }
}

// the above is NOT the same/logic as this below, even though it seems to be the same (see if you can understand why, can you understand the logic of it?):

if (CONDITION) {
  // scripting
} else if (CONDITION) {
  // scripting
} else {
  // scripting
}

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

Support

Forums