generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Printing a function

Previous Thread :: Next Thread 
cgjnm is not online. 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 is not online. 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 is not online. 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 is not online. iSymon
Joined: 19 Nov 2011
Total Posts: 1023
10 Dec 2015 09:36 PM
Commands:Kills(parameters) -- excuse me
Report Abuse
cgjnm is not online. 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 is not online. 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 is not online. 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 is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
10 Dec 2015 09:41 PM
Whoa, that works
Report Abuse
cgjnm is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image