Jump to content

The ultimate Lua tutorial


Recommended Posts

  Smart. said:
Good tutorial but maybe you should explain how you can use tables more efficiently, many people store simple information that's only used within the resource itself by using setElementData and getElementData when it can simply be used with a table and if you want to use it outside the resource you can use a simple export to return the table :)

Yes, I have noticed that with new scripters, lol. I'll go back later and add a "Table Efficiency" section :P

Link to comment

Update - Added commands!

Commands

  Reveal hidden contents
Link to comment
  • 1 month later...

Update -

Added the exports section, the tutorial is now complete!

Exports

  Reveal hidden contents
Link to comment
  • 2 weeks later...
  Smart. said:
Good tutorial but maybe you should explain how you can use tables more efficiently, many people store simple information that's only used within the resource itself by using setElementData and getElementData when it can simply be used with a table and if you want to use it outside the resource you can use a simple export to return the table :)

would be very nice if this tutorial topic had this as well

Link to comment
  • 3 weeks later...
  • 3 weeks later...
  • 2 weeks later...
  • 1 month later...

One bug i noticed is in The "Commands" section, in the "callbackFunct" Line 9, You get "attempt to compare nil with number",

it should be like this

if ( arg1 > 400 and arg1 < 611 ) then 

This is a great tutorial, but i wanted to take into notice this little problem, because most newbie scripters will not notice this.

I'm out.

Link to comment
  Danz said:
One bug i noticed is in The "Commands" section, in the "callbackFunct" Line 9, You get "attempt to compare nil with number",

it should be like this

if ( arg1 > 400 and arg1 < 611 ) then 

This is a great tutorial, but i wanted to take into notice this little problem, because most newbie scripters will not notice this.

I'm out.

Thanks, I fixed the code.

Link to comment
  • 1 month later...
  Callum said:
It might be worth making your tutorial make use of the predefined variables in MTA, such as 'root' and 'resourceRoot'. The amount of times I've seen people use getResourceRootElement(getThisResource()), when you can just use 'resourceRoot'. The same for getRootElement() and 'root'.

Thanks for the feedback.

I thought that this was a good idea, because I see this too lol. I added a section for it in the "General Lua" category, but i'ts pretty short because I wasn't too sure of what to put it in it.

Link to comment
  • 4 months later...
  • 2 years later...
  • 3 weeks later...

Hi,

Firstly, this tutorial is very good and really important for beginners. It can be developed, too. BTW, in Formatting Your Code section, you made a little mistake but it can confuse minds for beginners:

...
if (arg1 > arg2) then
	while ( arg1 > arg2 ) do  
		arg2 = arg2 + 1 
	end
...

Here, the arg1 variable already bigger than arg2. So, when this statement is true, while loop will start and one time it'll add 1 to arg2 variable. Then this loop ends... So that's correct:

...
if (arg1 > arg2) then
	while ( arg2 > arg1 ) do  
		arg2 = arg2 + 1 
	end
...

 

Thanks for this tutorial...

I hope that it is useful for beginners. (:

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...