PLEASE HALP!!! creating different responses based on score range

Im increasing the weight of the player and i want objects to respond differently within certain weight ranges. Changing as more food has been eaten i.e more weight has been gained. Please give me the most simple answer possible

so I got the second option to be read but i have a third one and although the score was over 120 it still read the response for 110

if (player.weight = 110) {
msg (""Looking good, all that hard work at the gym really paid off."")
}
else if (player.weight > 110) {
msg (""Crap! These pants must've shrunk in the wash."")
}
else if (player.weight > 120) {
msg (""I can't believe Mom and Dad still havent noticed my gut, guess I'll just have to stuff myself even more!"")


add "player.TimesEaten=0"
each time the player eats something...
player.TimesEaten=player.TimesEaten+1

then:
player eats an apple...
apple.weightgain= GetRandomInt(1,5)
player.weight=player.weight +( apple.weightgain * player.TimesEaten)


for the range (bound) handling, you use an 'if' Script, for example (in direct code scripting):

// from max to min:

if (test.score > 89) {
  test.grade = "A"
} else if (test.score > 79) {
  test.grade = "B"
} else if (test.score > 69) {
  test.grade = "C"
} else if (test.score > 59) {
  test.grade = "D"
} else {
  test.grade = "F"
}

// from min to max:

if (test.score < 60) {
  test.grade = "F"
} else if (test.score < 70) {
  test.grade = "D"
} else if (test.score < 80) {
  test.grade = "C"
} else if (test.score < 90) {
  test.grade = "B"
} else {
  test.grade = "A"
}

to do this in the GUI/Editor:

run as script -> add new script -> 'scripts' section/category -> 'if' Script -> (see below)

if [EXPRESSION] NAME_OF_OBJECT.NAME_OF_ATTRIBUTE OPERATOR VALUE_OR_EXPRESSION
-> then, add new script -> blah script(s)
else if -> add new script -> if [EXPRESSION] NAME_OF_OBJECT.NAME_OF_ATTRIBUTE OPERATOR VALUE_OR_EXPRESSION
-> then, add new script -> blah script(s)
// more or less 'else ifs'
else,
-> add new script -> blah script(s)

for pseudo example:

if [EXPRESSION] test.score > 89
-> then, -> set variable test.grade = [EXPRESSION] "A"
else if [EXPRESSION] test.score > 79
-> then, -> set variable test.grade = [EXPRESSION] "B"
else if [EXPRESSION] test.score > 69
-> then, -> set variable test.grade = [EXPRESSION] "C"
else if [EXPRESSION] test.score > 59
-> then, -> set variable test.grade = [EXPRESSION] "D"
else,
-> set variable test.grade = [EXPRESSION] "F"

or, you can use the 'switch' Script/Function too (they're the same thing functionally), but there's a trick to doing them due to how the 'switch' works (credit to Pixie):

(in direct code, as I'm lazy)

switch (true) {
  case (test.score > 90) {
    test.grade = "A"
  }
  case (test.score > 80) {
    test.grade = "B"
  }
  case (test.score > 70) {
    test.grade = "C"
  }
  case (test.score > 60) {
    test.grade = "D"
  }
  default {
    test.grade = "F"
  }
}

also, if you want to keep the Value within a Range (Bound), an example:

test.max_score = 100
test.min_score = 0

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

if (test.score > test.max_score) {
  test.score = test.max_score
} else if (test.score < test.min_score) {
  test.score = test.min_score
}

// note here that we've got two separate 'if' blocks (one above and one below this comment line/s), and not one 'if' block, as this is logically necessary, due to how if blocks (specifically the 'else-if/else' part of them) work:

if (test.score > 89) {
  test.grade = "A"
} else if (test.score > 79) {
  test.grade = "B"
} else if (test.score > 69) {
  test.grade = "C"
} else if (test.score > 59) {
  test.grade = "D"
} else {
  test.grade = "F"
}

this is NOT what you want to do:

test.max_score = 100
test.min_score = 0

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

if (test.score > test.max_score) {
  test.score = test.max_score
} else if (test.score < test.min_score) {
  test.score = test.min_score
} else if (test.score > 89) {
  test.grade = "A"
} else if (test.score > 79) {
  test.grade = "B"
} else if (test.score > 69) {
  test.grade = "C"
} else if (test.score > 59) {
  test.grade = "D"
} else {
  test.grade = "F"
}

as if your 'test.score' is greater/lesser than 100/0, then you won't be given a grade!

(see if you can understand the logic on your own, as it's a bit difficult to explain it)


This is what im working with i need it to do a printmessage but change based on weight this gives me an error can anyone help correct this so if player weight was either 111 or 115 it would read "Crap! These pants must've shrunk in the wash." Please help

if (player.weight = 110) {
msg (""Looking good, all that hard work at the gym really paid off."")
}
else if (player.weight = > 110) {
msg (""Crap! These pants must've shrunk in the wash."")
}


so I got the second option to be read but i have a third one and although the score was over 120 it still read the response for 110

if (player.weight = 110) {
msg (""Looking good, all that hard work at the gym really paid off."")
}
else if (player.weight > 110) {
msg (""Crap! These pants must've shrunk in the wash."")
}
else if (player.weight > 120) {
msg (""I can't believe Mom and Dad still havent noticed my gut, guess I'll just have to stuff myself even more!"")


GO FROM THE SCORE LATEST ACHIEVED IN THE GAME TO THE ONE SOONEST ACHIEVED. THIS WAY THE COMPUTER IS NOT STOPPED BY PREVIOUSLY APPLICABLE RESULTS


okay, for your third (last) response, let's look at the logic involved with the 'if' block:

if (player.weight = 110) { // if player.weight equals 100, then do the nested script(s) below, otherwise, goto/jump-to (and thus skip over the nested script(s) below) the 'else if (player.weight > 110)' line
  msg ("\"Looking good, all that hard work at the gym really paid off.\"")
}  else if (player.weight > 110) { // if player.weight is greater than 110, then do the nested script(s) below, otherwise if less than 110 (and also it's not equal to 110 as this was already checked for in the first line at the top: if player.weight=110), then goto/jump-to (and thus skip over the nested script(s) below) the 'else if player.weight > 120' line
  msg (""Crap! These pants must've shrunk in the wash."")
}  else if (player.weight > 120) { // since, your 'player.weight' Attribute's Value *IS* less than 110 (and also not equal to 110) to get to this line, obviously it doesn't meet this condition of if over 120, and thus you'll never ever have its nested script(s) run/activate/execute, as you can never get to this line with your 'player.weight' Attribute's Value over 120, as when it is, it gets handled already by the previous condition line: else if (player.weight > 110). So, you got an 'order of operations' logic error, you need to have the 'else if (player.weight > 120)' BEFORE (ABOVE) the 'else if (player.weight >110)', to correct it. See fix in the other code box below this one.
  msg (""I can't believe Mom and Dad still havent noticed my gut, guess I'll just have to stuff myself even more!"")
}

the fix:

if (player.weight = 110) {
  msg ("\"Looking good, all that hard work at the gym really paid off.\"")
}  else if (player.weight > 120) {
  msg ("\"I can't believe Mom and Dad still havent noticed my gut, guess I'll just have to stuff myself even more!\"")
}  else if (player.weight > 110) {
  msg ("\"Crap! These pants must've shrunk in the wash.\"")
}

// or, you might like this organization for the 'order of operations' better (a bit more logical-flowing):

if (player.weight > 120) {
  msg ("\"I can't believe Mom and Dad still havent noticed my gut, guess I'll just have to stuff myself even more!\"")
}  else if (player.weight > 110) {
  msg ("\"Crap! These pants must've shrunk in the wash.\"")
} else if (player.weight = 110) {
  msg ("\"Looking good, all that hard work at the gym really paid off.\"")
}
<!---
// optionally:
// more 'else ifs'
// optionally:
else {
  // blah script(s)
}
-->

the backslash ( \ ) character/symbol is known as an 'escape' ccharacter/symbol command, which tells quest, that the next character/symbol to the immediate right of it, is to be a string (displayed), for example:

(I'm not sure if any character/symbol will be displayed, or if it's only specific characters/symbols, such as the double quote)

msg ("Hi, my name is HK, what is your name?")
// output/result: Hi, name is HK, what is your name

vs

msg (""Hi, my name is HK, what is your name?", asked HK.")
// ouput/result: "Hi, my name is HK, what is your name?", asked HK.


the single quote ( ' ) character/symbol doesn't require the escape character/symbol ( \ ) for it to be displayed, as it's not a special/reserved character/symbol as a command for anything, it's just a normal character/symbol like the alphabetic character/symbols

the double quote ( " ) character/symbol is a special/reserved character/symbol command by quest, as it tells quest that anything inside of double quotes ( "xxx" ) is a String Value, and thus in order to to get around this, you got to use the escape character with the double quotes ( "xxx" ), which over-rides, and tells quest that in this case, the double quotes are NOT special/reserved character/symbol commands, they're just a normal character/symbol like the alphabet characters/symbols, and thus they get displayed just like those alphabet character/symbols do get displayed.


ask if you got any questions, or need any help, or if you still are not gettig the logic of the process of the 'if' block and its 'if / else if / else'


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

Support

Forums