Skip to content

Programming

Sander edited this page Dec 18, 2023 · 9 revisions

Programming With Nodes?

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.

Creating a DivideBy script

To begin we start with a Entry node to start your script.

entrynode

Then you can add and connect a Variable Table, to create 1 or multiple variables.

Connect 1

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.

addingfunctionlogic

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.

addedvariable

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.

finalresult

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😃

📖 Check our other web sources here:

Clone this wiki locally