-
-
Notifications
You must be signed in to change notification settings - Fork 11
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 easier. Meaning if I want to build a simple 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.
Right now we call the table a Divider and add a variable 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, this simply allows to print the divided number to any lua compiler.
Final generated syntax results
local Divider = {
Divide = 500,
}
local function Calculator()
local Splicer = Divider.Divide
print(Splicer / 2)
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 something in 2 you can use a online Lua compiler to check out the results.
Copyright © 2023, SanForge Studio & Lua Node Editor, All Rights Reserved. Licensed under the GNU General Public 3.0 License