Difference between revisions of "Conditions and Values"

From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 43: Line 43:
 
=== Display values ===
 
=== 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:
+
You may print out values as part of a text, both integer and string type values. Use the following markup:
 
* Integers: <code><v=value_name></code>
 
* Integers: <code><v=value_name></code>
 
* Strings: <code><vs=value_name></code>
 
* Strings: <code><vs=value_name></code>
Line 57: Line 57:
  
  
== Using conditions and (integer) values ==
+
== Build "if…else" queries ==
 
 
=== Build "if…else" queries ===
 
  
 
[[File:Game logic example.png|thumb|Try to open a locked chest]]
 
[[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.
 
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.
+
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.
  
  
=== Control object states ===
+
== Control object states ==
  
 
[[File:Object condition.png|thumb|Control object visibility through condition]]
 
[[File:Object condition.png|thumb|Control object visibility through condition]]

Revision as of 19:31, 8 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

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>


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."


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.


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.