skate1011
|
  |
| Joined: 13 Mar 2010 |
| Total Posts: 688 |
|
|
| 08 Sep 2012 09:42 PM |
well here I have a script that I made that should print the functions that are in the tables but it won't work. So here is the script anyone know anything?
funcs = {} funcs.hi = function hi() print("Hi") end; funcs.hello = function hello() print("Hello") end
for _, v in ipairs(funcs) do print(v.hi, v.hello) end
wiki.roblox.com |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 08 Sep 2012 09:47 PM |
Nothing will print for two reasons:
1) 'ipairs' only allows for numerical identifiers. You should use 'pairs' 2) Your 'v' variable in the loop would *be* 'funcs.hi' or 'funcs.hello', so you would just do 'print(v)' to print the function. |
|
|
| Report Abuse |
|
|
skate1011
|
  |
| Joined: 13 Mar 2010 |
| Total Posts: 688 |
|
|
| 08 Sep 2012 09:50 PM |
so I have this so far. But it still errors.
funcs = {} funcs.hi = function hi() print("Hi") end; funcs.hello = function hello() print("Hello") end
for i, v in pairs(funcs) do print(v) end
wiki.roblox.com |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 08 Sep 2012 09:52 PM |
| Forgot this the first time, but you are naming your functions twice. |
|
|
| Report Abuse |
|
|
skate1011
|
  |
| Joined: 13 Mar 2010 |
| Total Posts: 688 |
|
|
| 08 Sep 2012 09:53 PM |
So what would it be?
wiki.roblox.com |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
| |
|
skate1011
|
  |
| Joined: 13 Mar 2010 |
| Total Posts: 688 |
|
|
| 08 Sep 2012 09:57 PM |
how would I call it from the string? Just like funcs.hi ?
wiki.roblox.com |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 08 Sep 2012 10:01 PM |
local functions = {function hi() print("hi") end, function hello() print("hello") end}
functions[math.random(#functions)]() |
|
|
| Report Abuse |
|
|