View unanswered posts | View active topics It is currently Sun Aug 09, 2020 9:46 pm

 Page 1 of 1 [ 9 posts ]
 Print view Previous topic | Next topic
Author Message
REAL AMERICAN HERO

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
On syntax.

Syntax is the most important thing in any programming language, scripting language, any logical language ever.

Everything stays mostly the same across languages, the ONLY things that change are syntax and functions. SO! Let's get a little intro to syntax.

Lua is EXTREMELY SIMPLE. Fantastically simple! It's a wonderful language to learn.

Code:
if x == y then

Bam. That's it. That's it. That simple. BUT! You're not quite done yet.

Code:
if x == y then
y = y + 1
end

Now, this is just a little bit harder. If x is the same as y, increase y by 1. In Lua, you can refer to a variable inside its own definition. Now, notice the equals. In the if line, there's two of them. That means that it CHECKS if x is the same as y; it's a "traditional" equals. So what does a single equals sign do? It SETS something. y = y + 1 means that Y is set to itself, but one higher. Continually increasing.

AND THE MOST IMPORTANT THING: end. You absolutely have to make sure to end any logical statement. Otherwise, everything after the then will be DONE, rather than checked or whatever you want to have happen.

And now for the SECOND most important thing: nesting.

What if I wanted to have something checked, and then if that's true, having something else constantly done?

Code:
if x ~= y then
while y < x then
y = y + 1
end
end

See how the while goes INSIDE the if? That's absolutely one of the most important things programmers need to learn to do, and even if Lua is a fairly limited scripting language, it's good to do it properly. It helps legibility (for both you and anyone else looking at your code), it helps debugging, and it just looks better.

This applies to ALL logical statements. If, while, for, and also for things like functions.

ENDS LESSON 1

Mon May 18, 2009 12:07 am

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
you should post this in your on lua or whatever sticky

Mon May 18, 2009 12:18 am

Joined: Mon Jun 04, 2007 5:55 am
Posts: 1627
Location: Ohio
thats very helpful, I am serious. I didn't even notice 'while' even existed. I don't know how I missed that.

Mon May 18, 2009 4:52 am

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
im fairly sure its part of just about all readable languages. O_o
anyway, thanks for taking the time to post this grif. hopefully it'll make DRL's code more legible in general, and help ease people into Lua.

Mon May 18, 2009 5:03 am

Joined: Mon Jun 04, 2007 5:55 am
Posts: 1627
Location: Ohio
Geti wrote:
im fairly sure its part of just about all readable languages. O_o
anyway, thanks for taking the time to post this grif. hopefully it'll make DRL's code more legible in general, and help ease people into Lua.

some of grif's posts are doing a good job of helping that along, I suck at lua. Grif you should totally try to do a tutorial, you know, reserve all the posts for the front page and fill them in as you go. sort of put this all in one place.

Mon May 18, 2009 5:15 am
REAL AMERICAN HERO

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Naw I'll just get my mod buddies to remove all y'alls posts once I get motivated to do further parts.

Suggestions of things to cover?

Mon May 18, 2009 5:52 am

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
for loops, how to reduce lag by using timers to limit how often functions are used, how to define functions, tables (and how to iterate them), using math.random and math.floor to get usable numbers, vectors (surprised at how many people dont get how to use them..), areas, how to give relative positions, how to use trig to find distances rather than just using "boxed" distance calculation, common syntax errors and how to fix them, how to use MovableMan:AddActor, MovableMan:AddParticle, etc, how to add stuff to peoples inventory, fiddle with health, whatever else, commenting and why it is important (as well as how it is useful in debugging).
all those would help get a lot of people into Lua faster.
oh, also, yell about Lua being Lua and not lua or LUA or whatever else.

Mon May 18, 2009 6:37 am

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1358
Location: USA
Maybe make a simple lua mod from scratch to show the basic method of it all.

Mon May 18, 2009 3:04 pm

Joined: Mon Jun 04, 2007 5:55 am
Posts: 1627
Location: Ohio
The Mind wrote:
Maybe make a simple lua mod from scratch to show the basic method of it all.

This, step by step, to show the different times you can do things.

Mon May 18, 2009 5:24 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 9 posts ]

#### Who is online

Users browsing this forum: No registered users

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ Cortex Command    Dev Log    Wiki    Game Discussion    Game and Licensing Support    Mod Making       Lua Scripting       Requests    Mod Releases       Older Mods    Scene Releases       Scene Making Planetoid Pioneers    Game Discussion    Pioneer Program Lounge Data Realms Off-Topic    Off Topic Chat       Gaming       Forum Games    Site Support & Feedback