Variables are used to store information and they exist in almost all projects. The Create Variable shows the following window:
Name: is the name of the variable;
Value: contains the original (start) value of the variable
it informs Kwik if the variable content is a text, a number or a formula or command to be processed;
variable as formula/boolean to accept inputs like UI.Var + 1
it sets the variable as local, meaning it will exist only in the current page, or global, making the variable accessible to the entire project pages;
This is a Table: when enable, Kwik sets the variable as a Lua table (an array);
Comment: is an optional field that adds information about the variable in the generated code (this is nice if you are planning to learn with Kwik’s code or if you are going to have other people reading your project code);
Before/After layers are rendered: each layer content is part of a variable in Kwik’s code. If the variable you are creating is independent of any layer content, you should select the Before option. In the case your variable need to interact with a layer content, you must select After, otherwise you are going to have an issue with your variable trying to capture content that was not created yet.
Keep track: when checked, saves the content of the variable (and its updates) into an external file, managed by Kwik. Every time the variable is used in the future, instead using the original value, it will update with the content from the external file. This is great to keep track of scores, levels, etc.
Accessing Variable in codes
Kwik4 ‘s global table is _K
local _K = require “Application” _K.YOUR_GLOBAL_VARIABLE = 1
Local variable made with Create Variable is stored in UI table.
UI.YOUR_VARIABLE = 1