Difference between revisions of "Conditions and Values"

From The Official Visionaire Studio: Adventure Game Engine Wiki
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 at the key object or at the corresponding scene rather than at, 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 either the value of "true" or "false". You can create 2 types of conditions:<br/>
 +
#'''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 through logical operators ("and", "or", "negate"). It is not possible to directly set the value of combined conditions; their value results from the conditions 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 "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.
  
<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, but you can't change the string value 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 ===
 +
 
 +
The actual contents of both integer and string type values can be displayed as part of a text. Use this syntax to integrate values in your texts:
 +
* Integers: <code><v=value_name></code>
 +
* Strings: <code><vs=value_name></code>
  
  
<syntaxhighlight>
+
''Example 1:<br>Let's say you have an integer type value called "money" which contains the initial value of 100.''
-- let's say I have an integer value called "money" which contains the initial value of 100...
+
I currently have $<v=money>.
I currently have $<v=money>. -- would display "I currently have $100."
+
-- would display "I currently have $100."
 +
 
 +
''Example 2:<br>Let's say you have a string type value called "char1" which contains a character's name (which currently is set to "Fred").''
 +
My name is <vs=char1>.
 +
-- would display "My name is Fred."
 +
 
 +
 
 +
== Using conditions and (integer) values ==
 +
 
 +
=== Build "if…else" queries ===
 +
 
 +
[[File:Game logic example.png|thumb|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.
  
-- or let's say I have a "string" value "char1" which contains a characters name; let's say the characters name is "Fred"...
 
My name is <vs=char1>. -- would display "My name is Fred."
 
</syntaxhighlight>
 
  
 +
=== Control object states ===
  
<gallery widths=70px heights=70px perrow=4>
+
[[File:Object condition.png|thumb|Control object visibility through condition]]
File:condval_003.png
+
The second use case for conditions and values is linking them directly to objects, dialogs 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.
File:condval_004.png
+
{{toc}}
File:condval_005.png
 
</gallery>
 

Revision as of 18:00, 7 October 2022

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 at the key object or at the corresponding scene rather than at, 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 either the value of "true" or "false". You can create 2 types of conditions:

  1. 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.
  2. Combined: This allows you to combine several conditions through logical operators ("and", "or", "negate"). It is not possible to directly set the value of combined conditions; their value results from the conditions 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, but you can't change the string value 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

The actual contents of both integer and string type values can be displayed as part of a text. Use this syntax to integrate values in your texts:

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


Example 1:
Let's say you have an integer type value called "money" which contains the initial value of 100.

I currently have $<v=money>.
-- would display "I currently have $100."

Example 2:
Let's say you have a string type value called "char1" which contains a character's name (which currently is set to "Fred").

My name is <vs=char1>.
-- would display "My name is Fred."


Using conditions and (integer) values

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.


Control object states

Control object visibility through condition

The second use case for conditions and values is linking them directly to objects, dialogs 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.