Declaring variables?

jamrobeprom
18 Aug 2018, 14:46

I've had a look at the tutorial, and I can't figure out how to declare a variable.
I've tried all sorts, using the attributes tab, the "Set value of variable or attribute" script part, etc.
I'm sure the solution is simple and easy to understand and I'm just overthinking this.


Selsynn
18 Aug 2018, 16:18

You just have to set a value to your variable

YourVariableName= The value you want

With the gui it is with the Variable/Set a variable or attribute
You enter the name in the first input, the type of the creation in the second one. If it is Expression, you can affect a value directly in the third one


hegemonkhan
18 Aug 2018, 17:55

Quest has 3 types of VARIABLES (keeping this simple):

VARIABLES:

  1. Variables: temporary and local scope VARIABLE, won't cover them in this post
  2. Attributes: permanent (so long as its parent Object exists or still exists of course) and global scope VARIABLE
  3. Parameters: deals with Functions/Commands, won't get into them in this post

you want to use Attributes (Attribute VARIABLES), until/unless you learn/know coding and understand scope, the difference between and in usage of global Object's Attribute VARIABLES and local Element's scripting's Variable VARIABLES

thus, I'll show how to do Attributes, as this is what you want to be using


Attribute VARIABLES:


in the GUI/Editor:

'NAME_OF_OBJECT' Object -> 'Attributes' Tab -> Attributes (bottom box I think) -> Add -> (see below)

(Object Name: NAME_OF_OBJECT)
Attribute Name: NAME_OF_ATTRIBUTE
Attribute Type (drop down box): (String/Int:Integer/Boolean/Double/Object/Script/List/Dictionary)
Attribute Value: (whatever, but depends upon selected Attribute Type)


or, as scripting (in the GUI/Editor):

(whatever Element --- Objects' Script Attributes, Functions, Commands, Turnscripts, Timers, etc --- that can do scripting) -> run as script -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

(I use the '[EXPRESSION]' script option, as it allows you to directly type/code in what value or expression you want, as I don't have the GUI/Editor's Script options down, lol. My way of cheating around not knowing the GUI/Editor, hehe)

set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION

(vs in-code, as can see, the syntax is slightly different: NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION)

important: Quest parses the 'VALUE_OR_EXPRESSION', to determine/know what Attribute Type the Attribute is to be created as

for examples:

set variable player.strength = [EXPRESSION] 100 // Integer Attribute
set variable game.state = [EXPRESSION] 0 // Integer Attribute
set variable player.alias = [EXPRESSION] "HK" // String Attribute
set variable game.intro = [EXPRESSION] "Welcome to my game, I hope you enjoy it!" // String Attribute
set variable player.flying = [EXPRESSION] false // Boolean Attribute
set variable orc.dead = [EXPRESSION] false // Boolean Attribute
set variable game.paused = [EXPRESSION] true // Boolean Attribute

create ("katana") // creating a 'katana' Object
set variable katana.damage = [EXPRESSION] 50 // Integer Attribute
set variable player.weapon = [EXPRESSION] katana // Object (pointer/reference) Attribute

a more complex expression example (Integer Attribute):

set variable player.damage = [EXPRESSION] player.weapon.damage + player.weapon.damage * player.strength / 100


if you want to create/set/declare an Attribute VARIABLE and its initial Value and/or alter/change an Attribute's Value, via inputs during game play:

there's the 'get input' Script/Function:

(whatever Element --- Objects' Script Attributes, Functions, Commands, Turnscripts, Timers, etc --- that can do scripting) -> run as script -> add new script -> 'output' section/category -> get input' Script -> (see below, in-code example)

msg ("Name?")

get input {

  // quest automatically (hidden from you) stores your typed-in input (always as a String - but you can then convert it into another Data Type if/as needed) into the built-in 'result' Variable VARIABLE:

  // result = "YOUR_TYPED_IN_INPUT"

  player.alias = result // we then store the 'result' Variable VARIABLE's value or expression String into the built-in 'alias' String Attribute of the 'player' Player Object

  // essentially, what we are doing:

  // B = C
  // A = B
  // (A = B = C)
  // A = C

  // B <=== C
  // A <=== B
  // (A <=== B <=== C)
  // A <=== C

  // player.alias = result = "YOUR_TYPED_IN_INPUT"
  // player.alias = "YOUR_TYPED_IN_INPUT"

  // player.alias <=== result <=== "YOUR_TYPED_IN_INPUT"
  // player.alias <=== "YOUR_TYPED_IN_INPUT"

}

you can also create/add 'Command' Elements, which also are able to get typed-in inputs

and there's also the 'show menu / ShowMenu', 'ask/Ask', and etc Scripts/Functions that do menus (getting inputs as your menu item selections)