Website Home  HomeHome  PortalPortal  CalendarCalendar  FAQFAQ  SearchSearch  UsergroupsUsergroups  RegisterRegister  Log inLog in  
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Who is online?
In total there is 1 user online :: 0 Registered, 0 Hidden and 1 Guest

None

Most users ever online was 13 on Sat May 11, 2013 2:02 am
June 2019
MonTueWedThuFriSatSun
     12
3456789
10111213141516
17181920212223
24252627282930
CalendarCalendar

Share
 

 my basic lua tutorial

Go down 
AuthorMessage
Freedompal
Co-Lead GM
Co-Lead GM
Freedompal

Number of posts : 92
Age : 26
Location : behind you
Registration date : 2008-11-29

My Role Play Profile
Main Character Name:
Race:
Guild:

my basic lua tutorial Empty
PostSubject: my basic lua tutorial   my basic lua tutorial Icon_minitimeThu Apr 23, 2009 11:27 pm

lua scripting guide for you all this will cover basic statements helping you make some simple scripts or troubleshoot

pre made scripts

1 functions

2 statements
2.1 if
2.2 else
2.3 else if
2.4 values
2.5 calling functions

3 common errors





1 Functions

a lua script is basicly a bunch of Functions and variables that can be called on by events eg button click

a function should follow this basic format

Code:
Function example();

(contents)

end

other wise it wont work also If statements need to have a additional end example

Code:
Function Example2();

If variable1 then

Function1();

 end

end
these are just basic it is most likely they will be much more complex than these



2 Statements

statements can be used for a lot of things mainly adding multiple chooses or making sure the input is correct ill

cover a few basic ones here

2.1 If

if statements are used to make the function behave differently depending on factors for instance if you have a

password and it needs to be over 6 charters long

Code:
Function lenthcheck(inputlenth);


If (inputlenth >= 6) then;

invaildlenth();

else

Addpass(password);

 end

end

or another example

Code:
if (Wrotebyfreedompal == true) then;

SpellCheck();

end

the function above checks if the length of the input is less than 6 if it is it rejects it if it isn't then it

pass's on to another function

it work correctly they need 2 basic things: a condition to check, and a end


2.2 Else

else statements are used in If statements and tell the if statement what to do if the condition's isn't met for

example

Code:
if example1 then;

Function1();

else

Function2();

end

telling it that if the conditions isn't met then to carry out Function2 instead

2.3 Else if statements

else if statements are like else statements but tell it to check another condition of the first is not met

Code:
if example1 then;

funchtion1();

else if example2 then;

funchtion2();

end

so if example1 isn't met then it will check example 2 if none are met then it simply does nothing but you can also

use else statements to specify what to do if non of the conditions are met.

2.4 values
you can set the value of variables that is used though out the script or just within a function if needed like if

you want a function to loop but each time it does adds 1 you can set i to 1 and then have your looping function add

one each time

Code:
i = 1

function addone();

i = i + 1

end

this would be useful for a counter

2.5 calling functions
ive been pretty much doing this though out this but ill explain it anyway
if you use the same code a lot then it is easier to make it a function to save time and effort

Code:
Function Funchtion1();

z = x + y

if (z == 2) then

z = 3
y = 4
x = y x z
self = this
freedompal = "pwns icebound"

end


Function Funchtion2();

x = x + y

if (x == 39) then

z = 3
y = 4
x = y x z
self = this
freedompal = "pwns icebound"

end

for this it would be much easier to put



Code:
function shortened();

z = 3
y = 4
x = y x z
self = this
freedompal = "pwns icebound"

end

Function Funchtion1();

z = x + y

if (z == 2) then

shortened();

end

Function Funchtion2();

x = x + y

if (x == 39) then

shortened();

end


also you may want the result of a function to be passed onto another function

Code:
function addup();

x = input1
y = input2

z = x + y

showoutput(z);

end
this it adds up 2 numbers inputed into it and sends the answer to the output function


3 common errors

common errors like one letter wrong can cause errors but there so easy over look here's a few i make a lot

forgetting to add a end to a if statement will cause errors saying that a function isn't closed

not capitalizing the first letter of function names that are called when the first letter is capitalised in the name

or vise versa

spelling self explanatory

forgetting to add .. to strings when they are going to be part of text in the chat window example
Code:

sendchatmessage("hi" target)
should be
Code:
 sendchatmessage("hi"..target)

so double check scripts of your getting strange errors


if you feel i have put something in a hard to understand way feel free to ask me to explain or change it if you

understand it

_________________
my basic lua tutorial SIG
if you need me out of game email gm.freedomelf@googlemail.com
Back to top Go down
 
my basic lua tutorial
Back to top 
Page 1 of 1
 Similar topics
-
» Visual Basic Chess
» Ten Basic Checkmates to Know
» Curl Tutorial!
» AOE_Fan's RMS Command Tutorial
» How to make .abk book ( Arena ) step by step... tutorial...

Permissions in this forum:You cannot reply to topics in this forum
 :: Game Masters :: Tutorials-
Jump to: