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)


'counters' in the GUI/Editor are just Integer VARIABLES, usually used for 'counting' (addition by +1):

for example, in code:

// initial/old Value:
player.strength = 0

// incrementing/addition by +1 (in the GUI/Editor: the 'increase counter' script):
player.strength = player.strength + 1


// the Assignment Operation in programming:

the FINAL value on the right side of the equal sign is STORED INTO the VARIABLE on the left side of the equal sign

VARIABLE = VALUE_OR_EXPRESSION

// conconceptually:
// VARIABLE <=== VALUE_OR_EXPRESSION*

*the expression is done first, and its FINAL value/result is what is STORED INTO the variable

for examples:

VARIABLE = 5 + 10
// the FINAL value of '15' is STORED INTO the VARIABLE

VARIABLE = "mama" + "mia"
// this is known as 'concatenating' (literally putting together / next to each other), and involves Strings, such as "mama" and "mia"
// the FINAL value of 'mamamia' is STORED INTO the VARIABLE

Math's Addition vs String Concatenation:

5 + 5 = 10
55 + 55 = 110

"5" + "5" = "55"
"55" + "55" = "5555"
"mama" + "mia" = "mamamia"
"mama" + "5" = "mama5"


// conceptually, how the arithmetic (addition in this example) works with the Assignment Operation:

// player.strength (NEW) = player.strength (OLD: 0) + 1
// player.strength (NEW) = (0) + 1
// player.strength (NEW) = 1
//
// new value: player.strength = 1
//
// old value: player.strength = 1
//
// player.strength (NEW) = player.strength (OLD: 1) + 1
// player.strength (NEW) = (1) + 1
// player.strength (NEW) = 2
//
// new value: player.strength = 2
//
// etc etc etc


so, an example of how to do what you want in the GUI/Editor (Attribute VARIABLES and the 'if' Script usages)


Attribute VARIABLES usage:

creating our own custom Integer ("counter") Attribute VARIABLES, not using the built-in 'health' Integer Attribute VARIABLE:

'player' Player Object -> 'Attributes' Tab -> Attributes (box at the bottom) -> Add -> (see below, repeat as needed)

[Object Name: player]
Attribute Name: stamina
Attribute Type: int // (integer)
Attribute Value: WHATEVER_INITIAL_VALUE_YOU_WANT_IT_AT

[Object Name: player]
Attribute Name: life
Attribute Type: int // (integer)
Attribute Value: WHATEVER_INITIAL_VALUE_YOU_WANT_IT_AT

in code of the above example:

<object name=player">

  <inherit name="editor_object" />
  <inherit name="editor_player" />

  <attr name="stamina" type="int">WHATEVER_INITIAL_VALUE_YOU_WANT_IT_AT</attr>

  <attr name="life" type="int">WHATEVER_INITIAL_VALUE_YOU_WANT_IT_AT</attr>

</object>

the 'if' Script:

'WHATEVER SCRIPTING ELEMENT (Object's Script Attribute, Verb, Command, Function, Turnscript, Timer, etc)' Element -> (see below)

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

if [EXPRESSION] player.life < 100

-> then -> add new script -> 'output' section/category -> 'print a message' Script -> (see below)

print [EXPRESSION] "BLAH BLAH BLAH"

else if [EXPRESSION] player.stamina < 20

-> then -> add new script -> 'output' section/category -> 'print a message' Script -> (see below)

print [EXPRESSION] "BLAH BLAH BLAH"

as code, it'd look like this:

if (player.life < 100) {
  msg ("BLAH BLAH BLAH")
} else if (player.stamina < 20) {
  msg ("BLAH BLAH BLAH")
}

in code, example as a Function:

<game name="EXAMPLE">

  <attr name="start" type="script">

    example_function

    player.life = player.life - 100

    example_function

    player.life = player.life + 100
    player.stamina = player.stamina - 40

    example_function

    player.life = player.life - 100
    player.stamina = player.stamina - 10

    example_function

  </attr>

</game>

<object name="room">

  <inherit name="editor_room" />

</object>

<object name=player">

  <inherit name="editor_object" />
  <inherit name="editor_player" />

  <attr name="parent" type="object">room</attr>

  <attr name="stamina" type="int">150</attr>

  <attr name="life" type="int">50</attr>

</object>

<function name="example_function">
  if (player.life < 100) {
    msg ("ONE")
  } else if (player.stamina < 20) {
    msg ("TWO")
  } else {
    msg ("THREE")
  }
</function>

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

output:

THREE
ONE
TWO
ONE

as you can see... you may not want the logic design that you provided to us:

If Health = 100

then ( Message Here)

else If Health is < 100
Then (different message)

else if Stamina < 20
then (different message)

(err, I didn't see the first 'if health = 100' code line, my bad)

but still, you may need to adjust your logic design regardless

(if need help with the logic, ask, as its too complicated to explain, as there's many combinations of logic)

for a quick example, there's a big difference in logic between:

if (XXX) { XXX }
if (XXX) { XXX }
if (XXX) { XXX }

// all 3 'ifs' are done no matter what (all 3 'ifs' are always done)

vs

if (XXX) { XXX }
else if (XXX) { XXX }
else if (XXX) { XXX }

// the 'else ifs' are ONLY done if the previous (the one above) condition testing fails


Is this for a game book or text adventure? I have a feeling they handle counters differently, and I am not familiar with how game books do it.


Log in to post a reply.

Support

Forums