cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
|
| 10 Dec 2015 09:20 PM |
So I have a table (called Commands)
And each command is a function
How would I print the name of the function?
Commands = {} Commands.kill = function()
end
for i,v in pairs(Commands)do print(v) end
--output
function: 38FDAE30
So for a more layman approach,
How do I get it to print "kill" instead of 38FDAE30 |
|
|
| Report Abuse |
|
|
cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
|
| 10 Dec 2015 09:31 PM |
| I am making an Admin script and I want to be able to have a hint that says all of the Commands' names |
|
|
| Report Abuse |
|
|
iSymon
|
  |
| Joined: 19 Nov 2011 |
| Total Posts: 1023 |
|
|
| 10 Dec 2015 09:35 PM |
Try this...
Commands = { Kill = function(self, parameters) print("I kills da purson muahahahaha") end }
if Commands["Kill"] then Commands.Kill(parameters) end
|
|
|
| Report Abuse |
|
|
iSymon
|
  |
| Joined: 19 Nov 2011 |
| Total Posts: 1023 |
|
|
| 10 Dec 2015 09:36 PM |
| Commands:Kills(parameters) -- excuse me |
|
|
| Report Abuse |
|
|
cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
|
| 10 Dec 2015 09:37 PM |
Commands.kill = function(plr,p) if game.Players:FindFirstChild(plr.Name) then if plr.Character then plr.Character:BreakJoints() end end end Commands.jump = function(plr,p) if game.Players:FindFirstChild(plr.Name) then if plr.Character then if plr.Character:FindFirstChild'Humanoid' then plr.Character.Humanoid.Jump = true end end end end
for i,v in pairs(Commands)do print(v) end
I'm trying to print the name of the function without doing each function individually.
So like this:
--kill --jump etc |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 10 Dec 2015 09:39 PM |
for i,v in pairs(Commands)do print(i) end |
|
|
| Report Abuse |
|
|
cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
|
| 10 Dec 2015 09:40 PM |
| Isn't the first number in Variable,variable in pairs just the number of the item in the table? |
|
|
| Report Abuse |
|
|
cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
| |
|
cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
|
| 10 Dec 2015 09:44 PM |
another question with functions,
let's say I have this:
function kill() local desc = "Kills the player" --other script stuff end
Is there a way to access the "desc" from inside of the function? |
|
|
| Report Abuse |
|
|
cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
|
| 10 Dec 2015 09:48 PM |
Would it be something like
i.desc or v.desc? |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 10 Dec 2015 09:52 PM |
Commands = {} Commands.kill = { Action=function() end, Desc="Kills someone", Level=1, --etc }
|
|
|
| Report Abuse |
|
|
cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
|
| 10 Dec 2015 09:55 PM |
| Thanks, I didn't even think of that |
|
|
| Report Abuse |
|
|
Alpinu
|
  |
| Joined: 10 Jul 2010 |
| Total Posts: 108 |
|
|
| 10 Dec 2015 10:06 PM |
That works, but to use the command, you have to do Commands.kill.Action(). But yeah, that's the best way to do it! Now you can just go:
for i,v in pairs(Commands) do print(i .. ":",v.Desc) end |
|
|
| Report Abuse |
|
|
cgjnm
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
|
| 10 Dec 2015 10:10 PM |
Commands.commands = { Function = function(plr,p) local hint = Instance.new("Hint",workspace) for i,v in pairs(Commands)do if i ~= 'commands'then hint.Text = i..Suffix..Name..'. '..v.Desc wait(3) else hint.Text = i..' '..v.Desc wait(3) end end hint:Destroy() end; Desc = 'Shows a list of commands' }
:) It works |
|
|
| Report Abuse |
|
|