Jump to content

List of predefined variables.


Kenix

Recommended Posts

  • Moderators
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
Link to comment
  • 1 month later...
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.

Link to comment
  • 6 months later...
  • 1 month later...
  • 2 weeks later...
  • 2 years later...

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.)

Link to comment
  • 3 months later...
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
Link to comment
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.

 

Link to comment
  • qaisjp unpinned this topic

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...