Lua Basics
From Rigs of Rods Wiki
Contents |
Getting started
Before you can start using Lua, you need to have an editor, I use Notepad++, But notepad/Wordpad should be fine (Or ViM in Unix).
Variables
To store data in Lua, you need to have some variables!
myName = "John Smith"
You can also Combine Variables:
firstName = "John" lastName = "Smith" fullName = firstName.." "..lastName
This would make fullname "John Smith"
If you have Numbered variables, you can add them together
NumOne = 5 NumTwo = 5 myNum = NumOne+NumTwo
This would make myNum 10. Please note, that you cannot perform maths on Strings, if you do, RoR will crash.
Loops
If Loops
If you only want something to happen if a variable was a certain Value, you can use an If Loop myName = "John Smith"
if myName == "John Smith" then do --If myName is John Smith..
log("Hi John Smith!") --Would print "Hi John Smith!" to RoR.log
end --Tell Lua the loop ends here
For Loops
If you wanted a loop to repeat a certain amount of times, you can use a For loop.
for i=1,5 do
log("Hello! Loop Number: "..i)
end
This loop will print "Hello! Loop Number: X" to RoR.log 5 times. where X is a number from 1 to 5
Functions
If you want your Lua to be nice and Tidy, you will probably want to make custom functions!
function myFunc()
log("This is my Function!")
end --Tell Lua this is the end of the Function
Now, whenever you write myFunc() (In the same file...), it will print "This is my Function!" to RoR.log.
Functions can also have 'Parameters':
function myNewFunc(myName)
log("Hello "..myName..", How are you?")
end
myNewFunc("John Smith")
This will print "Hello John Smith, How are you?" in RoR.log


(gold)
(silver)
(bronze)

