### Author Topic: Tricks and tips for Lua scripting  (Read 2319 times)

0 Members and 1 Guest are viewing this topic.

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### Tricks and tips for Lua scripting
« on: June 11, 2011, 04:33:31 PM »
I've been poking around the net recently, and I found some interesting stuff about Lua. A fair bit of it seemed fairly obscure, at least to me, so I thought I'd share it with you guys.

• Lua is case sensitive. This isn't particulary obscure, and I'm sure you all knew it anyway, but some things that are posted my require this knowledge. FOO =/= foo =/= Foo
• For the purposes of logic false = nil and nil = false. Also, if I use either nil or false below, assume the other could be used.
• a, b = b, a will swap the values of the variable a and b. Presumably, though I haven't tested it, a, b, c = b, c, a will transpose all three one space to the left.
• a = a or b will make a = b, but only if a is nil or false (see above). c = a or b will do the same, but c will be given the value. If a is NOT nil, c =a.
• There is a very short method of writing simple if...else statements: condition and do if true or do if false  . This is very similar to the previous line, no?
• conditional1 and a or b  will return a if conditional is true, else it will return b.  --Orion63

Post any other things you know below. You will be credited.
« Last Edit: August 17, 2011, 03:34:27 PM by Pilchard123 »

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### Re: Tricks and tips for Lua scripting
« Reply #1 on: August 17, 2011, 01:07:08 PM »

--[[
commented stuff here
]]

If you add an extra - at the start of the block...

---[[
uncommented stuff here
]]

Thanks to Aino and Orion 63 for clarification.
« Last Edit: August 17, 2011, 03:56:39 PM by Pilchard123 »

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,483
• They'll eat you next!
• Eufloria: Yes
##### Re: Tricks and tips for Lua scripting
« Reply #2 on: August 17, 2011, 03:06:49 PM »
Heh, though you don't need the '--' at the end of the '--]]--'

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### Re: Tricks and tips for Lua scripting
« Reply #3 on: August 17, 2011, 03:18:57 PM »
At the end? I though you didn't need it at the start...

#### Orion63

• Sapling
• Thank You
• -Given: 0
• Posts: 73
• We are the Knights who say... NI!
##### Re: Tricks and tips for Lua scripting
« Reply #4 on: August 17, 2011, 03:28:22 PM »
conditional1 and a or b
It will return a if conditional is true, else it will return b.

i.e.
5 == 5 and 1 or 2 -> returns 1
5 == 12 and 1 or 2 -> returns 2

Also I recommend not using the or trick that often, since Eufloria itself(if not restarted) doesn't reset values, and if you're using the trick just to do something if the variable is not initialized, it will create some weird bugs(since the values will actually be initialized from the previous game).

Also, you don't need both '--' at the end, nor at the front.

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,483
• They'll eat you next!
• Eufloria: Yes
##### Re: Tricks and tips for Lua scripting
« Reply #5 on: August 17, 2011, 03:31:47 PM »
You need the double at the start of both of them, but not at the end.

#### Orion63

• Sapling
• Thank You
• -Given: 0
• Posts: 73
• We are the Knights who say... NI!
##### Re: Tricks and tips for Lua scripting
« Reply #6 on: August 17, 2011, 03:42:46 PM »

Hum...not in my editor...

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,483
• They'll eat you next!
• Eufloria: Yes
##### Re: Tricks and tips for Lua scripting
« Reply #7 on: August 17, 2011, 03:52:09 PM »
Lol, thats right xD

I face that problem when doing array inside of an arraybox, and I say wrong about it! I mean you need the double ONLY at the first!

#### Pilchard123

• Tester
• Old Oak
• Thank You
• -Given: 0
• Posts: 899
• Eufloria: Yes
##### Re: Tricks and tips for Lua scripting
« Reply #8 on: August 17, 2011, 04:05:25 PM »
Just OT a sec, is your avatar a glider from Game of Life, Orion?

#### Orion63

• Sapling
• Thank You
• -Given: 0
• Posts: 73
• We are the Knights who say... NI!
##### Re: Tricks and tips for Lua scripting
« Reply #9 on: August 17, 2011, 04:16:41 PM »
Yap ^^. Good days when I spent entire days, shooting gliders against each other to see if I could make an awesome pattern :-P(Actually, it was last year, but still ^^)

#### Bonobo

• Achiever
• Old Oak
• Thank You
• -Given: 77
• Posts: 629
• Was born, still alive.
• Eufloria: Yes
##### Re: Tricks and tips for Lua scripting
« Reply #10 on: August 18, 2011, 01:51:09 AM »
Amazing, the story of Conways Game of Life. I am 54 now, and I remember being 11 or 12 years old (1968 or ’69), and I got a “boys’ book” with an article about this “new” game and how scientists “wasted” thousands of \$\$ “playing” Life on computers the size of houses, and how I played this with checkers stones  … and how exciting this was.

BTW am I the oldest here? Could it be? *1957

Greetz, Tom
Do you play Go? (aka iGo aka Baduk aka Weiqi)

#### Orion63

• Sapling
• Thank You
• -Given: 0
• Posts: 73
• We are the Knights who say... NI!
##### Re: Tricks and tips for Lua scripting
« Reply #11 on: August 18, 2011, 02:06:05 AM »
I am way younger(16), so... Game of Life it's pretty much exclusive to the computer ^^, but it's still pretty damn fascinating. Good to know, that there are still enthusiastics out there and that I am not the only one being fascinated by a zero-player game ^^
« Last Edit: August 18, 2011, 04:14:17 PM by Orion63 »

#### Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,483
• They'll eat you next!
• Eufloria: Yes
##### Re: Tricks and tips for Lua scripting
« Reply #12 on: August 18, 2011, 03:57:28 PM »
16? Nice, I'm 15, but you might have recognized from the signature I had

#### Bonobo

• Achiever
• Old Oak
• Thank You
• -Given: 77
• Posts: 629
• Was born, still alive.
• Eufloria: Yes
##### Re: Tricks and tips for Lua scripting
« Reply #13 on: August 18, 2011, 08:23:08 PM »
hahaha, and sorry for the OT, but I must let you know that I remember the time very well when 15 was SOOOO much younger than 16
Do you play Go? (aka iGo aka Baduk aka Weiqi)

• Ent
• Thank You
• -Given: 1