Jump to content




A Simple Tutorial For The Newbies


2 replies to this topic

Poll: A Simple Tutorial For The Newbies (22 member(s) have cast votes)

Was This Tutorial Helpful

You cannot see the results of the poll until you have voted. Please login and cast your vote to see the results of this poll.
Vote Guests cannot vote

#1 jay5476

  • Members
  • 289 posts

Posted 11 August 2013 - 06:44 AM

working with strings, and variables
this is a tutorial on how to work with different things in lua
"string" -- is a string
var = "string" -- is a variable containing the string "string"
table = {"string1", "string2"} -- now a table is defined by curly braces {}
now the above isnt very useful you need to now how to work with these,
strings:
Spoiler
variables:
Spoiler
working with functions, tables and loops
Spoiler
now onto tables and loops:
Spoiler
thank you for reading this tutorial and if you have any questions please post below
i might be adding more later

#2 RandomMcSomethin

  • Members
  • 18 posts

Posted 14 August 2013 - 07:44 PM

Thx for the loops! I need to learn more, for I am a feeble newbie.

for i=10 do
print "I'm a noob"
end

#3 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 10 September 2014 - 01:25 PM

Could you space out your code a bit? It feels like a lot of walls of code.
Adding extra blank lines at points where you end a loop and start another point will help people read your code easier (i.e. "oh, a blank line, that means that we are moving on in to a new section of code")

Another tip, put indents in your loops, readers can then easily identify what's in the loop and what is not.

Example with both tips implemented:
for i = 1, #table do -- #table is how many variables table contains, it returns a number
	 print(table[i]) -- i = the number of times it has looped so on the first time table[i] is really table[1]
end -- close your for loop

-- you could also use pairs
for key, value in pairs(table) do -- now there is to variables defined by this function 'key' and 'value'
	 --[[ now basicly
	 key = number of looped times
	 value = table[key]
	 ]]--
	 print(value) -- print the current variable in table
end -- close your for loop

Edited by Lupus590, 10 September 2014 - 01:27 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users