←  Tutorials

ComputerCraft | Programmable Computers for Minecraft

»

Some lua tricks you may not have known...

Kingdaro's Photo Kingdaro 20 Aug 2012

EDIT: Hey, it's me from the future. Lots of stuff has changed, one of those things being that I'm not all that interested in CC or Lua that much anymore. But it seems like some people are still stumbling upon this (badly written) post! Since there's still some interest in it, thanks to SquidDev, you can view the full formatted post here. The rest of this post remains, as always, for reference.

---

I've rewritten the Lua Tricks tutorial and hosted it on my github page. You can access it here: http://kingdaro.gith...lua-tricks.html

Old content for reference:

Spoiler

Edited by Kingdaro, 25 February 2019 - 08:28 AM.
Quote

FuzzyPurp's Photo FuzzyPurp 20 Aug 2012

Nice Thread!
Quote

Cranium's Photo Cranium 20 Aug 2012

I learned a few things here! +1 for you!
Quote

Kingdaro's Photo Kingdaro 20 Aug 2012

Thanks guys. :D/>
Quote

Graypup's Photo Graypup 24 Aug 2012

Nice, now we just have to convince the noobs to read programming in lua :D/>.
Quote

Kingdaro's Photo Kingdaro 24 Aug 2012

Reformatted the post and reorganized/added some more information.
Quote

nitrogenfingers's Photo nitrogenfingers 24 Aug 2012

Nice topic, picked up a few tips I wasn't familiar with. Thanks for posting!

One small thing though, you mention you can use strings to access non-string indexed fields in tables. That's actually another little eccentricity in lua as the statements
table example = {
  ["a"] = 1;
  ["b"] = 2;
}
and
table example = {
  a = 1;
  b = 2;
}

Are actually equivalent, which also means that

print example.a
and
print example["a"]

Are also equivalent. I learnt that a few weeks ago, rather nice bit of syntactic sugar.
Quote

TntTerminal's Photo TntTerminal 26 Aug 2012

Thank you this helped me a lot! Especially using a ' instead of a " because when i type a " nothing appears, but when i type anything else it appears but what i typed dont. For example: if i type: "hello" It appears "ello" so i need to type "h" two times, i dont know why.
Quote

Noodle's Photo Noodle 27 Aug 2012

Nice work!
Quote

ETHANATOR360's Photo ETHANATOR360 31 Aug 2012

very good +1
Quote

kaj's Photo kaj 01 Sep 2012

Thanks for this.
Favorited / +1
I'm finding this really helpful.
Quote

Jajnick's Photo Jajnick 03 Sep 2012

Everybody who have checked lua-users wiki knows that...
Quote

Kingdaro's Photo Kingdaro 03 Sep 2012

 Jajnick, on 03 September 2012 - 10:02 AM, said:

Everybody who have checked lua-users wiki knows that...
The people here tend to have not even have heard of lua before discovering ComputerCraft.
Quote

Jajnick's Photo Jajnick 03 Sep 2012

 Kingdaro, on 03 September 2012 - 06:49 PM, said:

 Jajnick, on 03 September 2012 - 10:02 AM, said:

Everybody who have checked lua-users wiki knows that...
The people here tend to have not even have heard of lua before discovering ComputerCraft.
That's interesting! I was exactly in the same situation, and the first thing I've done was checking Google, keyword: lua tutorial. First result? Lua-users.
Have those people not heard of Google? I don't think so.

There is no excuse for human thoughtlessness. Understand it.
Quote

Cloudy's Photo Cloudy 03 Sep 2012

He's just sharing his knowledge. Sure it can be found elsewhere, but I don't see the harm in it being here.
Quote

Kingdaro's Photo Kingdaro 03 Sep 2012

 Jajnick, on 03 September 2012 - 07:16 PM, said:

That's interesting! I was exactly in the same situation, and the first thing I've done was checking Google, keyword: lua tutorial. First result? Lua-users.
Have those people not heard of Google? I don't think so.

There is no excuse for human thoughtlessness. Understand it.
I'm basing my knowledge of others' knowledge through looking at the programs people have displayed, and as far as I've seen the examples I've given have been scarcely used.

 Cloudy, on 03 September 2012 - 07:29 PM, said:

He's just sharing his knowledge. Sure it can be found elsewhere, but I don't see the harm in it being here.
Exactly this.
Quote

NIN3's Photo NIN3 04 Sep 2012

You sir, deserve a one up. Thank you for making my scripts just a wee bit neater!
Quote

FuzzyPurp's Photo FuzzyPurp 06 Sep 2012

 NIN3, on 04 September 2012 - 01:45 AM, said:

You sir, deserve a one up. Thank you for making my scripts just a wee bit neater!

Then click the + button at the bottom right of his initial Post. 9 people have so far it seems.
Quote

Kingdaro's Photo Kingdaro 08 Sep 2012

Still adding on as I learn more wonderful things about lua's flexibility.

Thanks for the rep, guys. :D/>
Quote

sjele's Photo sjele 08 Sep 2012

This is nice :D/>

"Scrolling up to hit +1"
Quote