Kenix

List of predefined variables.

Recommended Posts

Server only

client -- the client that called the event

btw what will this be?

a userdata?

can I check with this, if the one that did send it, is still in the server?

Edited by Guest

Share this post


Link to post
Server only

client -- the client that called the event

btw what will this be?

a userdata?

can I check with this, if the one that did send it, is still in the server?

Just to answer the question: it will return the client that called the event. If you trigger some server-side event from client-side, the client will be the player who triggered the server-side event. This is useful for checking element data hacks and similiar. Quite a helpful thing with security.

Share this post


Link to post

I would personally recommend adding global vars like ROOTELEMENT, RESROOTELEMENT, LOCALPLAYER (upper case) so most of the text editors light them up as constants.

Share this post


Link to post

There are certain rules in the programming communities when it comes to variable names.

Share this post


Link to post

Kenix is there any update for the varibles ? or just these ?

Share this post


Link to post

We don't have any updates in predefined variables as far i know.

Share this post


Link to post

You're missing 'arg'.

'arg' is a predefined Lua variable in functions which use '...' as an argument. Example:

crun function a(...) outputChatBox(tostring(arg.n)) end a(10, 20, 30) -- "3" (arg.n returns 3 because there were 3 arguments in ...)

crun function a(...) outputChatBox(tostring(arg[2])) end a(10, 20, 30) -- "20" (arg[2] returns 20 because the second argument in ... is 20.)

Share this post


Link to post
On ٢٧‏/٥‏/٢٠١٧ at 11:52, Arran said:

You're missing 'arg'.

'arg' is a predefined Lua variable in functions which use '...' as an argument. Example:

crun function a(...) outputChatBox(tostring(arg.n)) end a(10, 20, 30) -- "3" (arg.n returns 3 because there were 3 arguments in ...)

crun function a(...) outputChatBox(tostring(arg[2])) end a(10, 20, 30) -- "20" (arg[2] returns 20 because the second argument in ... is 20.)

You'r wrong ..

You Should Define "arg" by yourself to get the results , and
'arg.n' its wrong , the Correct is '#arg'
the examples will be :

function a(...) local arg = { ... }; outputChatBox(tostring(#arg)) end a(10, 20, 30) -- "3" (arg.n returns 3 because there were 3 arguments in ...)

function a(...) local arg = { ... }; outputChatBox(tostring(arg[2])) end a(10, 20, 30) -- "20" (arg[2] returns 20 because the second argument in ... is 20.)


 

  • Confused 1

Share this post


Link to post
1 hour ago, iMr.WiFi..! said:

You'r wrong ..

You Should Define "arg" by yourself to get the results , and
'arg.n' its wrong , the Correct is '#arg'
the examples will be :


function a(...) local arg = { ... }; outputChatBox(tostring(#arg)) end a(10, 20, 30) -- "3" (arg.n returns 3 because there were 3 arguments in ...)

function a(...) local arg = { ... }; outputChatBox(tostring(arg[2])) end a(10, 20, 30) -- "20" (arg[2] returns 20 because the second argument in ... is 20.)


 

Actually, arg is indeed predefined, and does contain a key-value pair of n which lists the number of arguments.

Quote

The three dots (...) in the parameter list indicate that the function has a variable number of arguments. When this function is called, all its arguments are collected in a single table, which the function accesses as a hidden parameter named arg. Besides those arguments, the arg table has an extra field, n, with the actual number of arguments collected.

-- https://www.lua.org/pil/5.2.html 

You can check it yourself using the following function (perhaps on HTTP runcode):

function hey(...)
  return inspect(arg)
end

--then call 
hey(553, 674, "test", "foobar")
-- This will return a formatted table containing all the arguments you've inputted, without actually defining the variable "arg", and there's also the "n" key in there.

 

Share this post


Link to post

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.