{if flag:} help

I am a beginner here and I want to know how the flag works. I don't know any coding whatsoever and I have no idea what that is for.


A flag is used to indicate if an object in your game is one state or another. Doors and containers have a flag callled "locked", when it is on, the exit or container is locked, when it is off, the thing is unlocked. There are several other flags built-in: Containers also have "isopen", objects and exits have "visible", rooms have "visited".

You can add your own too. It the tutorial (I think) a flag is used for the dead guy; it gets turned on when he is brought back to life.

By the way, flags are also called Booleans, and said to be true or false. Just different words for the same thing.

Looks like you want to use a flag in the text processor. You could do this for the description of an old chest (just the first line - the rest is explanation!):

The chest is old. {if chest.isopen:The lid is open.}
                  ^ Start of the text processor directive
                        ^ "chest" is the name of the object
                              ^ "isopen" is the flag
                                        ^ The bit after the colon is what is displayed, if the flag is set (true)
                                                   ^ End  of the text processor directive

If the "isopen" flag is on (true), the player sees:

The chest is old. The lid is open.

Otherwise she sees this:

The chest is old.

If you want text for when the flag is off, you can use not:

The chest is old. {if chest.isopen:The lid is open.}{if not chest.isopen:The lid is closed.}

Now the player will see this if the chest is closed:

The chest is old. The lid is closed.


I'm not the best at explaining stuff... but I'll try to help... (ignore/forget my post if it confuses you more! Pixie or others will help you better than I can)

this might be more difficult without getting into explaining more than just this (as it'll confuse you)... but I'll try to help you with understanding how the '{if flag:}' works

the format (known as 'syntax' in programming and maybe human languages too --- not an English major, lol) is this (from here: http://docs.textadventures.co.uk/quest/text_processor.html -- scroll down to the 'Game Book' section):

{if flag:text}
Display text only if flag is set

and (the opposite, 'negation', aka 'not'):

{if not flag:text}
Display text only if flag is not set

I think starting with some conceptual examples, will better help with trying to help this make sense to you, as I try to explain it/them...

{if player.flying: You are flying, weeee!} {if not player.flying: You are NOT flying, boo hoo}


player.flying = true
msg ("{if player.flying: You are flying, weeee!} {if not player.flying: You are NOT flying, boo hoo}")
// output: You are flying, weeee!

player.flying = false
msg ("{if player.flying: You are flying, weeee!} {if not player.flying: You are NOT flying, boo hoo}")
// output: You are NOT flying, boo hoo

// conceptually:
{if player.flying = true, then output: You are flying, weeee!} {if player.flying = false (not true = false: if false), then output: You are NOT flying, boo hoo}


about Booleans (true/false), basic Boolean Logic:

(I don't like the term 'flags' being used specifically for Booleans, but in this case, for the '{if flag:text/string output}' it is, sighs)

dragon.dead = true // conceptually/effectively/logically: the dragon is dead
dragon.dead = false // conceptually/effectively/logically: the dragon is alive

not dragon.dead = true // conceptually/effectively/logically: the dragon is alive
not dragon.dead = false // conceptually/effectively/logically: the dragon is dead

dragon.alive = true // conceptually/effectively/logically: the dragon is alive
dragon.alive = false // conceptually/effectively/logically: the dragon is dead

not dragon.alive = true // conceptually/effectively/logically: the dragon is dead
not dragon.alive = false // conceptually/effectively/logically: the dragon is alive

you can choose to use 'dead' or 'alive' for your Boolean Attribute Name, but not both (pick one or the other), as they do the same thing, just a matter of which you prefer (such as which makes more sense to you) and/or for the situation, of whether to use 'alive' or 'dead' for this example.


so....

msg ("{if NAME_OF_OBJECT.NAME_OF_BOOLEAN(FLAG)_ATTRIBUTE: YOUR_TEXT(STRING)_OUTPUT}")

replace my capitolized stuff with what you created/got/want in your game, for example...

For the Game Book, you only got two Objects that you can add Attributes to:

the 'player' Player Object and the 'game' Game Settings Object

msg ("{if player.NAME_OF_BOOLEAN(FLAG)_ATTRIBUTE: YOUR_TEXT(STRING)_OUTPUT}")
or
msg ("{if game.NAME_OF_BOOLEAN(FLAG)_ATTRIBUTE: YOUR_TEXT(STRING)_OUTPUT}")

let's say you want/created this custom (your own) Boolean (Flag) Attribute: 'rich', which can be added to either the 'player' Player Object or the 'game' Game Settings Object or even added/given to both the 'player' Player Object and the 'game' Game Settings Object:

msg ("{if player.rich: YOUR_TEXT(STRING)_OUTPUT}")
and/or
msg ("{if game.rich: YOUR_TEXT(STRING)_OUTPUT}")

lastly, you put in what you want your text (string) output to be for if that condition (if player/game.rich) is true:

msg ("{if player.rich: being rich, you buy yourself a beautiful diamond ring}")
and/or
msg ("{if game.rich: being rich, you buy yourself a beautiful diamond ring}")


unfortunately, this is a bit confusing:

'player.flying = true' can be written as 'player.flying', as quest is programmed to understand that this means '=true'

whereas, if you want something to be false, you got to do this 'player.flying = false' or 'not player.flying'

so, it gets a bit confusing... just try to rmember that 'OBJECT_NAME.BOOLEAN(FLAG)_ATTRIBUTE_NAME' is a shortened form of this: 'OBJECT_NAME.BOOLEAN(FLAG)_ATTRIBUTE_NAME = true'


also, about the 'msg ("xxxxxxxxx")'

this is just how the 'print a message' Script looks in code, the use of the '{if flag:text}' has to be used within a 'print a message' script, but I think the GUI/Editor handles this already for you, as you're likely already choosen the 'print a message' Script before you're able to choose the '{if flag:text}' or if you're trying to use it yourself if it's not a Script option in the GUI/Editor.

I think you can use the '{if flag:text}' with the 'print a message -> print [MESSAGE]' Script option... but if not, then you need to change it to this script option: 'print a message -> print [EXPRESSION]'


also note that we can do something more complex to, for an example:

msg ("Hi, my name is {player.alias}, {if player.sex = male: a male} {if player.sex = female: a female}, and I am {player.age} years old. I like playing {random:soccer:football:baseball:basketball}. {if game.state=0: What is your name?} {if game.state=1: Would you like hang out some time?} {if game.state=2: Would you like to go to a movie with me some time?}")


the text processor commands are a much more simple way of doing complex string expressions/outputs/concatenations (fancy programming term for literally putting stuff together, so it's not the same as math addition/adding), whereas the 'normal' (non text processor commands) way, looks like this:

string_variable = "Hi, my name is " + player.alias + ","
if (player.sex = "male") {
  string_variable = string_variable + " a male, "
} else if (player.sex = "female") {
  string_variable = string_variable + " a female, "
}
string_variable = string_variable + " and I am " + player.age + " years old. I like playing "
stringlist_variable = split ("soccer;football;baseball;basketball", ";")
integer_variable = GetRandomInt (0, ListCount (stringlist_variable) - 1)
sport_string_variable = StringListItem (stringlist_variable, integer_variable)
string_variable = string_variable + sport_string_variable + ". "
if (game.state = 0) {
  string_variable = string_variable + "What is your name?"
} else if (game.state = 1) {
  string_variable = string_variable + "Would you like to hang out some time?"
} else if (game.state = 2) {
  string_variable = string_variable + "Would you like to go to a movie with me some time?"
}
msg (string_variable)

so, you can see, if you can use them, the text processor commands are much much more nice... though this way gives you the full functionality, but it's a lot more complex (for the most part), than using text processor commands.


does this kinda help with understanding how to use the '{if FLAG:text}' Game Book text processor command, or did I just completely confuse you more?


Data Types:

computers are stupid, you have to tell them what you're working with, and these types have to match up too, whereas we humans do/understand this stuff naturally.

String Values:

(you can use most symbols/characters but not all of them)
(anything with the double quotes, is a String)

"a"
"abc"
"dragon"
"dog_cat_1"
"fkd3o_nno_weo2n2n dno3 seja_wa"

Boolean Values:

true
false

Integer (int - quest uses this shortened form) (non-decimal numbers) Values:

-999999999, -100, -3, 0, 5, 300, 666666666

Double (Floats/Floating Points: decimal numbers) Values:

-9999.123, -1.7, 0.0, 4.95867565466, 9999999999.8

Object Values:

any non-numerical (non-Integer and non-Double) and any non-special/non-reserved words (such as 'true' and 'false', 'this', and etc..) that is NOT encased in the double quotes, and that already actually exists within your game, for example:

<object name="player">
  <attr name="right_hand" type="object">unarmed</attr>
</object>

<object name="unarmed">
</object>

<object name="sword">
</object>

// pretend we got scripting somewhere that changes our weapon (stored in our 'player.right_hand' Object Attribute) from 'unarmed' to 'sword':

player.right_hand = sword // NO error

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

vs

<object name="player">
  <attr name="right_hand" type="object">unarmed</attr>
</object>

<object name="unarmed">
</object>

// pretend we got scripting somewhere that changes our weapon (stored in our 'player.right_hand' Object Attribute) from 'unarmed' to 'sword':

player.right_hand = sword // ERROR! there is no 'sword' Object!

and the more complex Data Types:

Lists, Dictionaries, and etc... but too tired to get into them now...


Thanks everyone! I think I understand now. But how do you set what the flag is. I get the options, like how something is or isn't in this particular condition by using true and false. But how do you switch it on and off? In hegemonkhan's example involving whether or not you're flying, there was player.flying = true. How do you set that into the code? Like do I have to put in extra commands or surround it in a bracket or something?


you do so by setting/re-setting/changing/altering/adjusting the Boolean Attribute's Value to 'true' (toggled 'on' state/condition) or 'false' (toggled 'off' state/condition)

Boolean Attribute:

NAME_OF_OBJECT.NAME_OF_BOOLEAN_ATTRIBUTE = VALUE

VALUE is either: 'true' or 'false'

NAME_OF_OBJECT.NAME_OF_BOOLEAN_ATTRIBUTE = true // conceptually: your Boolean Attribute is toggled as being in the 'on' state/condition
NAME_OF_OBJECT.NAME_OF_BOOLEAN_ATTRIBUTE = false // conceptually: your Boolean Attribute is toggled as being in the 'off' state/condition


in/via the GUI/Editor:

run as script -> add new script -> 'variables' section/category -> 'set object flag' for '=true', or: 'unset object flag' for '=false'

in code (using a Function for the scripting Element, but you can use whatever Element you want: a Verb, Command, Turnscript, etc):

you can do so like this directly (the 'dot' notation/scripting --- has to be put within an Element/location which can do scripting):

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = true // it's is currently set/re-set to being 'on'
NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = false // it's is currently set/re-set to being 'off'

<function name="example_function">
  player.flying = true // the player is now effectively set/re-set to be flying
  player.flying = false // the player is now effectively set/re-set to be NOT flying
  player.flying = true // the player is now effectively set/re-set to be flying again
  player.flying = false // the player is now effectively set/re-set to be NOT flying again
  // etc etc etc (not that you'd be endlessly switching the 'flying' state/condition back and forth like this, lol)
</function>

or, you can use the 'set' Function (has to be put within an Element/location which can do scripting):

set (player, "flying", true)
set (player, "flying", false)

<function name="example_function">
  set (player, "flying", true)
  set (player, "flying", false)
  set (player, "flying", true)
  set (player, "flying", false)
  // etc etc etc (not that you'd be endlessly switching the 'flying' state/condition back and forth like this, lol)
</function>

or, you can use the GUI/Editor's helper Functions (I think these do exist)... but too lazy to open up the GUI/Editor, and see what they're called...


if you're somewhat understanding this code/scripting stuff and are interested in learning more in coding/scripting ... you can try taking a look here for a more detailed guide on this type of stuff:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk


here's an example of showing the differences between setting/re-setting/changing/altering a (Boolean) Attribute's Value and doing an action (the 'if' Script) based upon that (Boolean) Attribute's Value:

<object name="tv">

  <attr name="is_turned_on" type="boolean">false</attr> // it's initial state (as code scripting it'd look like this): tv.is_turned_on = false

  <attr name="watch_tv" type="script">
    if (tv.is_turned_on = true) {
      msg ("You watch the local news that is on tv")
    } else if (tv.is_turned_on = false) {
      msg ("You stare at the blank black screen, as you never turned the tv on... (you dummy!)")
    }
  </attr>

  <attr name="turn_on_tv" type="script">
    if (tv.is_turned_on = true) {
      msg ("The tv is already turned on, silly!")
    } else if (tv.is_turned_on = false) {
      tv.is_turned_on = true
      msg ("You turn on the tv")
    }
  </attr>

   <attr name="turn_off_tv" type="script">
    if (tv.is_turned_on = true) {
      tv.is_turned_on = false
      msg ("You turn off the tv")
    } else if (tv.is_turned_on = false) {
      msg ("The tv is already turned off, silly!")
    }
  </attr>

</object>

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

Support

Forums