General > Developers Corner
Learning Lua... (Just a random post from a lua super noob.)
Neku:
Want me to explain what's going on in mine?
syn.:
yes please neku:) I really don't like tables now
syn.:
20! Jam it's 20! you freaking added 100 and 99 into the table for no reason... starts at 0 because c = 0 and then goes up by one all the way to 20 because you put x[3] and 20 is your 3rd variable (or whatever it's called) and n = c and blahblahblah. I want more jam pls:D
edit* : just checked on SciTE and I'm pretty sure I'm right.
Neku:
Think of tables as variables inside of a variable.
I went a tad further and made tables within the table.
To call a table's value, you would do
--- Code: ---table[x]
--- End code ---
Say I wanted to call the point value of Pig Molester.
I would do
--- Code: ---MEDAL[3][3] -- Another [] because it's inside another table.
--- End code ---
Bytewave:
--- Quote from: syn. on January 24, 2014, 11:20:50 PM ---20! Jam it's 20! you freaking added 100 and 99 into the table for no reason... starts at 0 because c = 0 and then goes up by one all the way to 20 because you put x[3] and 20 is your 3rd variable (or whatever it's called) and n = c and blahblahblah. I want more jam pls:D
edit* : just checked on SciTE and I'm pretty sure I'm right.
--- End quote ---
I think I might have one for you...
Simple, but weird if you don't know it all...
--- Code: ---tab = {
"Billy",
"Bob",
"Joe"
}
math.randomseed( tonumber( tostring( os.time()):reverse():sub( 1, 6 ) ) )
print( "Winner: " .. tab[ math.random( 3 ) ] )
--- End code ---
Yep, more tables. C:
I could've just posted my raffle name picker code, but its function namings and heavy commenting are too easily understandable... :p
EDIT: *crosses fingers and hopes I didn't screw anything up while typing on a lag guy as heck iPod tough 4G with autocorrect on*
EDIT 2: Fixed a few blatant syntax errors (probably added a few too) and added spacing.
EDIT 3: Fixed a blatant syntax error that I should've noticed but didn't due to my 20/100 uncorrected vision and my usage of a mobile device to make this post (I have switched to a computer since then :P).
EDIT 4: Tabs! :D
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version