-
-
Notifications
You must be signed in to change notification settings - Fork 9
Programming
To program with these nodes we first have to understand some basic logic about Lua. Like most programming and scripting languages, you have variables, functions, operators, Control Structures etc, you are probably wondering why should I use nodes?
To give an example our nodes act the same as writing the logic itself only visually. Meaning if I want to build a simple mathmatical script to divide something using a function, we can see how this unfolds.
To begin we start with a Entry node to start your script.
Then you can add and connect a Variable Table, to create 1 or multiple variables.
We call the table a Divider and add a variable entry called Divide with a value of 500, it can be any nummeric value that you want. By having just that node it can already give you a output when generating your code
Generated syntax results
-- Added the Variable table
local Divider = {
Divide = 500,
}
If you did that successfully the code above should also be your generated code syntax.
To continue we can create a function declaration and a function call node to insert further logic. I call my function Calculator
As it will have the division logic inserted.
Generated syntax results
local Divider = {
Divide = 500,
}
local function Calculator() -- added the function
end
Calculator() -- Added the function call
If you did that successfully the code above should also be your generated code syntax.
Next you can add a single variable node to specify the Variable Table and the Variable value name by adding the value statement Divider.Divide
I called this variable Splicer
.
Generated syntax results
local Divider = {
Divide = 500,
}
local function Calculator()
local Splicer = Divider.Divide -- added the variable
end
Calculator()
If you did that successfully the code above should also be your generated code syntax.
After you added the variable you can simply add a Divide and a Print node, and hook them to eachother like the sample image, this simply allows to print the divided number in 2, to any lua compiler.
Final generated syntax results
local Divider = {
Divide = 500,
}
local function Calculator()
local Splicer = Divider.Divide
print(Splicer / 2) -- Added the print and divide operation.
end
Calculator()
If you did that successfully the code above should also be your generated code syntax.
If you did all of this then you have succesfully divided 500 in 2 using pure visual logic. You can use any online Lua compiler to check out the results. in which the output will be 250. So to challenge yourself more, make it more advanced, why not try it with a forloop or a while loop😃
Copyright © 2023, SanForge Studio & Lua Node Editor, All Rights Reserved. Licensed under the GNU General Public 3.0 License