Skip to content

Programming

Sander edited this page Dec 10, 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 easier. Meaning if I want to build a simple 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

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.

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, this simply allows to print the divided number to any lua compiler.

finalresult

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 any online Lua compiler to check out the results.

📖 Check our other web sources here:

Clone this wiki locally