Difference between revisions of "Conditions and Values"

From The Official Visionaire Studio: Adventure Game Engine Wiki
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
<strong>Conditions & Values</strong> are a fundamental necessity when it comes to game development as they allow us to dictate the <span class="italic bold">events</span> that can take place, have taken place or have yet to take place. They can also be used in <span class="green italic">if else</span> queries to determine if an event, or multiple events should be allowed to occur based on a conditions value or the integer number of a value.
+
<strong>Conditions and Values</strong> are a fundamental necessity when it comes to game development as they allow us to dictate the events that can take place, have taken place or have yet to take place. They can also be used in "if…else" queries to determine if an event, or multiple events should be allowed to occur based on a condition's value or the integer number of a value.
 +
 
 +
Both conditions and values can be defined in various locations throughout the editor; there are "Conditions" and "Values" tabs everywhere. From the engine's perspective it doesn't matter where you add them, because they are accessible from anywhere. To keep track of your game logic it makes sense though to add them in places where they logically belong. – ''If you need a condition called "key_taken" to control the visibility of a key object, you should add this condition to the key object or to the corresponding scene rather than to, let's say a character that appears somewhere else in your game. But wherever you put it, you may always link it for setting the state/visibility of your key.''
  
  
 
== Conditions ==
 
== Conditions ==
<strong>Conditions</strong> are boolean based & contain either the value of <span class="green">true</span> or <span class="red">false</span>. Besides the obvious use of them in an <span class="italic" style="color:lightgreen">if else</span> query, they can also be linked directly to objects, dialogs & interface buttons via the properties tab for the aforementioned objects, to quickly determine if the object is active (shown) or disabled (hidden); if disabled then all images & animations for the object will be hidden & all actions associated with the object will also be disabled - this is very useful for quickly changing the environment of the scene or any other scenes for that matter, regardless of whether they are a playable scene, cut-scene or menu.
 
  
 +
[[File:Conditions.png|thumb|Adding conditions]]
 +
<strong>Conditions</strong> are boolean based variables and contain a value of either "true" or "false". You can create 2 types of conditions:<br/>
 +
* <span class="inlinecode>Variable:</span> This is a single condition which contains a boolean value of "true" or "false". When adding it, you define an initial value and can change that value at any time during the game through the [[Action Parts#Change condition|"Change condition"]] action part.
 +
* <span class="inlinecode>Combined:</span> This allows you to combine several conditions, values, and Lua queries through logical operators ("and", "or", "negate"). It is not possible to set the value of combined conditions directly; their value results from the variables/statements it is made up of.
  
You can create 2 types of conditions:<br/>
 
1. <strong>Variable</strong>: this is a single condition which contains a boolean value of true or false.<br/>
 
2. <strong>Combined</strong>: this allows you to link 2 single conditions & set "and", "or" query to link to an object.
 
  
 +
== Values ==
  
Combined conditions can be useful, but I find Values are a lot more flexible when it comes to multiple conditions needing to be met for certain events to be performed. The in editor if query system is not as flexible as writing if queries with Lua mind, as there is no method for creating the "<span class="green">and</span>" or "<span class="green">or</span>" operators.
+
=== Integer variables ===
  
 +
[[File:Values.png|thumb|Adding values]]
 +
<strong>Values</strong> are first and foremost integer based variables. When adding them, you define an initial value which may be a fixed or a random number from a range you set. During the game you have multiple options inside of the [[Action Parts#Set value|"Set value"]] action part such as directly setting a new integer value (=), adding to current value (+), subtracting from current value (-), multiplying current value (*), and dividing the current value (/). You can also link another value variable to take its number value. The [[Action Parts#Set random value|"Set random value"]] action part allows you to set a random value.
  
<gallery widths=70px heights=70px perrow=4>
 
File:condval_000.png
 
File:condval_001.png
 
File:condval_002.png
 
</gallery>
 
  
 +
=== String variables ===
  
== Values ==
+
It is also possible to use a value as a string variable instead of as an integer variable. You may set the initial string when adding the value, but you can't change the string via the "Set value" or any other action part, nor can you use the string value in an action part "if…else" query or link it to an object. You need Lua scripting to make use of string type values:
<strong>Values</strong> are "string" & integer based & are a lot more flexible than conditions. We can create "string" values, integer values & random integer values between x number (min) & y number (max). We also have multiple options inside of the "set value" action part such as directly setting a new integer value (=), adding to current value (+), subtracting from current value (-), multiplying current value (*) & finally: dividing the current value (/). Having said that; we can't set a new string value via the "set value" action part, nor can we use the string value in an if else query; instead it has to be done via a simple bit of Lua scripting (see below).
 
  
 +
<syntaxhighlight lang="lua">
 +
-- example of handling string type values with lua
 +
local val = Values["add_value_name_here"] -- store value into a variable
 +
local str = val.String -- store linked value's "string" value into a variable
  
<syntaxhighlight>
+
val.String = "add new string value here" -- create a new string value
-- for simplicities sake, this should be done inside of an "execute a script" action part!
 
local val = getObject("Values[add value name here]") -- store value into a variable
 
local str = val:getStr(VValueString) -- store linked values "string" value into a variable
 
  
val:setValue(VValueString, "add new string value here") -- create a new string value
 
  
 
-- quick if query example
 
-- quick if query example
Line 41: Line 41:
  
  
Values, both integer & "string" can be called inside of the displayed text action parts. Currently I do not see much point in calling string values inside of displayed text until support for true text input has been added to Visionaire Studio, but the integer value can be used for various different things such as keeping track of money, credits, score of a game or a puzzle etc.
+
=== Display values ===
 +
 
 +
You may print out values as part of a text, both integer and string type values. Use the following markup:
 +
* Integers: <span class="inlinecode><v=value_name></span>
 +
* Strings: <span class="inlinecode><vs=value_name></span>
 +
 
 +
 
 +
See the [[Text#Display_values|text page]] for some examples.
 +
 
 +
 
 +
== Build "if…else" queries ==
 +
 
 +
[[File:Game logic example.png|thumb|250px|Try to open a locked chest]]
 +
The obvious use of conditions and values is for building your game logic through "if…else" queries: if a condition is true, do one thing; if it is false, do another thing. Or: if a value is greater than 5, do one thing; if it is less than 5 but greater than 0, do a second thing; if it is less than 0, do a third thing.
 +
 
 +
Use the "If condition" and "If value" action parts to create these structures. There are more [[Action Parts#Condition.2C_If.2C_Value|"If" action parts]] available querying other aspects of the game, such as "If character has item", "If character is on scene", or "If language is current language".
  
  
<syntaxhighlight>
+
== Disable/Enable objects ==
-- let's say I have an integer value called "money" which contains the initial value of 100...
 
I currently have $<v=money>. -- would display "I currently have $100."
 
  
-- or let's say I have a "string" value "char1" which contains a characters name; let's say the characters name is "Fred"...
+
[[File:Object condition.png|thumb|250px|Control object visibility through condition]]
My name is <vs=char1>. -- would display "My name is Fred."
+
The second use case for conditions and values is linking them directly to objects and interface buttons via the "Properties" tab for the aforementioned objects, to quickly determine if the object is active (shown) or disabled (hidden). If disabled then all images and animations for the object will be hidden and all actions associated with the object will also be disabled; the cursor will not recognize the object anymore. This is very useful for quickly changing the environment of the scene or any other scenes for that matter, regardless of whether they are a playable scene, cut-scene or menu.
</syntaxhighlight>
+
 
 +
Besides objects and interface buttons, you can also disable/enable dialog parts by linking a condition or a value to them.
 +
 
 +
 
 +
== Link conditions and values quickly ==
  
 +
[[File:Link condition.png|thumb|200px|"Drag" a link to the condition]]
 +
If you want to link a condition or value, you usually click the link button and then navigate to the desired variable in the dialog window. There is a useful feature in the Visionaire editor to enhance that workflow. You can "drag" a connection out of the link button (see image) and drop it onto the condition or value. This is not limited to conditions and values but also works for other elements, like objects. The link button and the element you want to link have to be visible in the editor at the same time though, so you won't reach everything using that method.
  
<gallery widths=70px heights=70px perrow=4>
+
<div style="clear:both"></div>
File:condval_003.png
+
{{toc}}
File:condval_004.png
 
File:condval_005.png
 
</gallery>
 

Latest revision as of 11:31, 16 January 2024

Conditions and Values are a fundamental necessity when it comes to game development as they allow us to dictate the events that can take place, have taken place or have yet to take place. They can also be used in "if…else" queries to determine if an event, or multiple events should be allowed to occur based on a condition's value or the integer number of a value.

Both conditions and values can be defined in various locations throughout the editor; there are "Conditions" and "Values" tabs everywhere. From the engine's perspective it doesn't matter where you add them, because they are accessible from anywhere. To keep track of your game logic it makes sense though to add them in places where they logically belong. – If you need a condition called "key_taken" to control the visibility of a key object, you should add this condition to the key object or to the corresponding scene rather than to, let's say a character that appears somewhere else in your game. But wherever you put it, you may always link it for setting the state/visibility of your key.


Conditions

Adding conditions

Conditions are boolean based variables and contain a value of either "true" or "false". You can create 2 types of conditions:

  • Variable: This is a single condition which contains a boolean value of "true" or "false". When adding it, you define an initial value and can change that value at any time during the game through the "Change condition" action part.
  • Combined: This allows you to combine several conditions, values, and Lua queries through logical operators ("and", "or", "negate"). It is not possible to set the value of combined conditions directly; their value results from the variables/statements it is made up of.


Values

Integer variables

Adding values

Values are first and foremost integer based variables. When adding them, you define an initial value which may be a fixed or a random number from a range you set. During the game you have multiple options inside of the "Set value" action part such as directly setting a new integer value (=), adding to current value (+), subtracting from current value (-), multiplying current value (*), and dividing the current value (/). You can also link another value variable to take its number value. The "Set random value" action part allows you to set a random value.


String variables

It is also possible to use a value as a string variable instead of as an integer variable. You may set the initial string when adding the value, but you can't change the string via the "Set value" or any other action part, nor can you use the string value in an action part "if…else" query or link it to an object. You need Lua scripting to make use of string type values:

-- example of handling string type values with lua
local val = Values["add_value_name_here"] -- store value into a variable
local str = val.String -- store linked value's "string" value into a variable

val.String = "add new string value here" -- create a new string value


-- quick if query example
if str == "hello world" then
 return true
else
 return false
end


Display values

You may print out values as part of a text, both integer and string type values. Use the following markup:

  • Integers: <v=value_name>
  • Strings: <vs=value_name>


See the text page for some examples.


Build "if…else" queries

Try to open a locked chest

The obvious use of conditions and values is for building your game logic through "if…else" queries: if a condition is true, do one thing; if it is false, do another thing. Or: if a value is greater than 5, do one thing; if it is less than 5 but greater than 0, do a second thing; if it is less than 0, do a third thing.

Use the "If condition" and "If value" action parts to create these structures. There are more "If" action parts available querying other aspects of the game, such as "If character has item", "If character is on scene", or "If language is current language".


Disable/Enable objects

Control object visibility through condition

The second use case for conditions and values is linking them directly to objects and interface buttons via the "Properties" tab for the aforementioned objects, to quickly determine if the object is active (shown) or disabled (hidden). If disabled then all images and animations for the object will be hidden and all actions associated with the object will also be disabled; the cursor will not recognize the object anymore. This is very useful for quickly changing the environment of the scene or any other scenes for that matter, regardless of whether they are a playable scene, cut-scene or menu.

Besides objects and interface buttons, you can also disable/enable dialog parts by linking a condition or a value to them.


Link conditions and values quickly

"Drag" a link to the condition

If you want to link a condition or value, you usually click the link button and then navigate to the desired variable in the dialog window. There is a useful feature in the Visionaire editor to enhance that workflow. You can "drag" a connection out of the link button (see image) and drop it onto the condition or value. This is not limited to conditions and values but also works for other elements, like objects. The link button and the element you want to link have to be visible in the editor at the same time though, so you won't reach everything using that method.