Variables

Are variables persistent? I created a variable string list in the Start Script, but when I try to reference that variable in a room script it states that the variable doesn't exist.


(filler for getting my edited post, updated/posted, argh)


quest has three main types of VARIABLES...

VARIABLES:
-> (1) a 'Variable' VARIABLE
-> (2) an 'Attribute' VARIABLE
-> (3) an/a 'Argument/Parameter' VARIABLE

the 3 VARIABLES:

(1) Variable: local/temporary, it gets destroyed upon the scripting containing it, ending/completing (it's scope/existance is limited to the scripting creating its created/used in. A Variable can't be used outside of the scripting that created it). Some examples (built-in and custom/self-created Variables): result = VALUE_OR_EXPRESSION, result = "HK", result = HK // (the 'HK' has to be an actual existing Object), result = 0, result = true, result = false, handled = true, handled = false, you_go_first_initiative = true, you_go_first_initiative = false, count = 0, count = 4, count = count + 5, weapon = katana // (the 'katana' has to be an actual existing Object), etc etc etc

generic (concept) syntax:

NAME_OF_Variable = VALUE_OR_EXPRESSION

(2) Attribute: global/permanent (so long as the Object containing it, exists / still exists, of course), some examples: player.alias = "HK", game.state = 0, player.strength = 100, orc.dead = false, orc.dead = true, player.weapon = katana, player.damage = player.weapon.damage + player.weapon.damage * player.strength / 100, etc etc etc

generic (concept) syntax:

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION

(3) Arguments/Parameters: deals with Functions and Commands, they're more complicated, so not explaining them here right now.


an example of local scope (Variables) vs global scope (Attributes):

<game name="example_game">

  <attr name="start" type="script">
    
    msg (example_object.example_integer_attribute) // no error
    // result/output: 0
    
    example_object.example_integer_attribute = example_object.example_integer_attribute + 5 // no error
    msg (example_object.example_integer_attribute) // no error
    // result/output: 5 // (0+5=5)

    example_object.example_integer_attribute = example_object.example_integer_attribute + 5 // no error
    msg (example_object.example_integer_attribute) // no error
    // result/output: 10 // (5+5=10)

    do (example_object, "example_script_attribute") // no error
    // results/displayments/outputs:
    // 0
    // 7
    // 14

   msg (example_integer_variable) // ERROR! (there is no 'example_integer_variable' existing to be used here, so display the 'ERROR!' message for this coding/scripting issue)

   example_integer_variable = example_integer_variable + 3 // ERROR! (there is no 'example_integer_variable' existing to be used here, so display the 'ERROR!' message for this coding/scripting issue)

    msg (example_integer_variable) // ERROR! (there is no 'example_integer_variable' existing to be used here, so display the 'ERROR!' message for this coding/scripting issue)
    
  </attr>

</game>

<object name="example_object">

  <attr name="example_integer_attribute" type="int">0</attr>

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

    example_integer_variable = 0 // no error // we're creating and setting this Variable and its (initial) Value
    msg (example_integer_variable) // no error
    // result/display: 0

    example_integer_variable = example_integer_variable + 7 // no error // we're creating (over-writing / over-riding the old Variable) and (re-)setting this Variable and its (new) Value (as a 'complex' Expression: addition operation/expression, the expression is still using the old Variable and its old Value, before it gets over-writen/over-riden, to get more technical-detailed-accurate explanation of it)
    msg (example_integer_variable) // no error
    // result/display: 7 // (0+7=7)

    example_integer_variable = example_integer_variable + 7 // no error // we're creating (over-writing / over-riding the old Variable) and (re-)setting this Variable and its (new) Value (as a 'complex' Expression: addition operation/expression, the expression is still using the old Variable and its old Value, before it gets over-writen/over-riden, to get more technical-detailed-accurate explanation of it)
    msg (example_integer_variable) // no error
    // result/display: 14 // (7+7=14)

  </attr>

</object>

with quest, you usually want to be using Attributes for their global scope.

if you were to be writing/coding a program using the main full-bore programming languages (C++, Java, Python), then global VARIABLES/Functions/etc are to be avoided (too complicated to explain why here), but they're great for how quest is designed and for game-making too.


Great.

One other question. How do you put a line break or carriage return into a string list variable so when its printed out values are shown on different lines?


(filler for getting my edited post, updated/posted, grr)


you'll have to manually do/create the list displayment yourself (or edit the built-in 'show menu / ShowMenu' Scripts/Functions), well there's probably/maybe a way to insert the line spacing-breaks into your list items, and the parser will recognize it... KV or Pixie or MrAngel can help with whether it can be done (and how) or not...

(I'm still not really knowledgeable on this type of syntax using the html/xml '<br>' and etc, formatting code yet myself with quest. You'll probably need to use the 'CDATA' tag code block too for it, I think)

here's how to manually create the same list displayment as 'show menu / ShowMenu' Scripts/Functions (but with the added spacing between the items' displayment):

(showing an example with numbering, but you can take those code lines out and/or adjust the code, if you don't want/need the numbering)

numbering_integer_variable = 0
foreach (item_variable, NAME_OF_OBJECT.NAME_OF_LIST_ATTRIBUTE) { // or: foreach (item_variable, NAME_OF_LIST_Variable) {
  numbering_integer_variable = numbering_integer_variable + 1
  msg (numbering_integer_variable + ". " + item_variable)
  msg ("") // one way of doing a line space-break / carriage return
}

// output/results:

1. ITEM_1
(line space-break)
2. ITEM_2
(line space-break)
3. ITEM_3
(line space-break)
etc etc etc (more or less items -- depends on your list's number/quantity of items, of course)
(line space-break)

if you want them as hyperlinks... let me know... I think I can help you with how to do the syntax for/to make them into clickable hyperlinks. pretty sure I can.. lol


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

Support

Forums