Jump to content

[TUT]Basics for beginners lua scripting


DiGiTal

DO YOU LIKE THIS TUTORIAL  

9 members have voted

  1. 1. Do you like this tutorial ?

    • ye, useful kinda
      6
    • No, it suck
      3


Recommended Posts

Y7uITA7.png

 

Hello, I'm simple scripter lua mtasa and designer .Enjoy my first tutorial (any question reply it or suggestion, i'll do a list of tutorials )
Variables(type):
*Global variables: means the variable will be avaible on hole of the script  for example:

Code:
function test()
name = 123
jake = "me"
end
function test()
name = 123
jake = "me"
end

function test1()
 print(name)--- returns 123
 print(jake)------returns me
end

 

the ----- it's a advert can't cause anything to the code

print it's for to output a string or else.

or (because as global variable it can be in the function or out.)
 

Code:
name = 123
jake = "me"
functio test()
------your code
end

 



*Local variables: it will be avaible only on your function attached to.

Code:
function test()
local name = 123
local jake = "me"
end

and if i do

function test()
local name = 123
local jake = "me"
end

function testt()
  print(jake) ----- return nil
  end

 


If you saw

Code:
jake = "me"

 

"me" called a string .

*Key words

and    break    do    else    elseif    end    false    for    if
in     local    nil   not     repeat    then   return   true   or  
until    while    function



*Function : The function is the way that describe your goal by a CODE . it likes
 

Code:
function NameOfYourFunction(arguments)
-----YOUR CODE

end

 


The function end with "end" if you forgot it , your code wrong.


*nil : it means nothing
*boolean: it return true or false value
*if : Is for to state "if" it ends with "end" as for function  for ex:
 

local var1=1
local var2=2
function name()
if (var1+var2) == 3 then
-----do somthing
else
-----do something else
end end

 


means if 2+1 = 3 then insert your code BUT if 2+1 ~= 3 then insert your code (xd)
~= means not equal
== equal
*operators: it's what your learned at school :Big Grin (+,-,/,*,^)

(I'll update it soon)

Edited by DiGiTal
  • Like 3
Link to comment

It would be good if you indent your codes: 

local var1=1
local var2=2

function name()
    if (var1+var2) == 3 then
	    -----do somthing
    else
	    -----do something else
    end 
end

function test()
    local name = 123
    local jake = "me"
end

function testt()
    print(jake) ----- return nil
end

It is easier to read. 

  • Like 1
Link to comment
  • Recently Browsing   0 members

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