View unanswered posts | View active topics It is currently Tue Apr 16, 2024 4:43 pm



Reply to topic  [ 9 posts ] 
 A LITTLE HEADS UP 
Author Message
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post A LITTLE HEADS UP
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.

Let's start with the first thing any intro to logic should start with. An IF statement.

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
Profile
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post Re: A LITTLE HEADS UP
you should post this in your on lua or whatever sticky


Mon May 18, 2009 12:18 am
Profile
User avatar

Joined: Mon Jun 04, 2007 5:55 am
Posts: 1627
Location: Ohio
Reply with quote
Post Re: A LITTLE HEADS UP
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
Profile YIM WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: A LITTLE HEADS UP
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
Profile WWW
User avatar

Joined: Mon Jun 04, 2007 5:55 am
Posts: 1627
Location: Ohio
Reply with quote
Post Re: A LITTLE HEADS UP
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
Profile YIM WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: A LITTLE HEADS UP
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
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: A LITTLE HEADS UP
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
Profile WWW
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post Re: A LITTLE HEADS UP
Maybe make a simple lua mod from scratch to show the basic method of it all.


Mon May 18, 2009 3:04 pm
Profile
User avatar

Joined: Mon Jun 04, 2007 5:55 am
Posts: 1627
Location: Ohio
Reply with quote
Post Re: A LITTLE HEADS UP
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
Profile YIM WWW
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users


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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.049s | 15 Queries | GZIP : Off ]