Jump to content

Scripting


Moony

Recommended Posts

I recently started learning LUA and its things.

Someone sent me this example of a LUA file and as usual, i dont understand it.

function test ( player )
local name = getPlayerName ( player )
outputChatBox ( name )
end
 
function testB ( player )
outputChatBox ( getPlayerName ( player ) )
end
 
addCommandHandler ( "command1", test)
addCommandHandler ( "command2", testB)

I'd like to know the following things:

Definitions of:

-"local"

-"getPlayerName ( player )"

-"outputChatBox ( name )"

-"addCommandHandler ( "command1", test)

addCommandHandler ( "command2", testB)"

Basically its every meaning of every part of the function.

Thanks very much!

Link to comment
function test ( player ) -- our function name.. according to wiki page of addCommandHandler (click below on addCommandHandler), 1st argument is player element (more about elements in link below) who triggered function
-- link for elements help [url=https://wiki.multitheftauto.com/wiki/Element]https://wiki.multitheftauto.com/wiki/Element[/url]
local name = getPlayerName ( player ) -- we are getting name of player element passsed with addCommandHandler
outputChatBox ( name ) -- we are writing that name in chatbox
end -- end of function
 
function testB ( player ) -- same
outputChatBox ( getPlayerName ( player ) ) -- shortened version of function "test", we are not storing any variables
end -- ..
 
addCommandHandler ( "command1", test) -- if player type "/command1" in chatbox - [b]test[/b] function will be fired
addCommandHandler ( "command2", testB) -- if player type "/command2" in chatbox - [b]testB[/b] function will be fired

I'd like to know the following things:

Definitions of:

-"local"

-"getPlayerName ( player )"

-"outputChatBox ( name )"

-"addCommandHandler ( "command1", test)

addCommandHandler ( "command2", testB)"

Basically its every meaning of every part of the function.

Thanks very much!

rly weird way to learn scripting..

- local:

http://www.lua.org/pil/4.2.html

and rest are described PERFECTLY on wiki (click on function name in script above to be redirected to wiki)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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