Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
|
| 17 Jul 2014 09:57 PM |
Lets say I have a table like so;
local Table = {5,7}
How would I be able to get a variable for each value in the table? So like;
local Var1 = 5 local Var2 = 7 |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 09:58 PM |
Why would you need to? You already have access to the variables in the table
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
|
| 17 Jul 2014 10:01 PM |
| I need to use them to call a function, and Var1 and Var2 are the parameters. Is there an easier way to do this? |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 10:03 PM |
t = {6,5,4}
print(t[1], t[2], t[3]) > 6 5 4
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
|
| 17 Jul 2014 10:07 PM |
| Thing is, the variables are user-inputted, and I don't know how many numbers are going to be in the table. |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 10:09 PM |
How do you know which numbers to put into your function?
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
|
| 17 Jul 2014 10:15 PM |
| Hmm. I suppose thats a problem. Do you have any idea how I could do this? |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 10:16 PM |
What are you trying to do with all of this?
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
|
| 17 Jul 2014 10:20 PM |
| Essentially a very customizable admin commands script. The player can custom create a function with as many arguments as you want or whatever and the script will do everything for you. |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 10:24 PM |
I'm still not entirely sure what you're trying to do, could you explain a little more in depth?
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
|
| 17 Jul 2014 10:26 PM |
Well basically its a script that runs functions from the chatbar, like a Command Prompt. You can go in the script and type a function and it will create that command. The thing is, I don't know how many arguments the player needs for his custom function, thats why I need to figure out to do this.
If that makes sense, I understand if it doesn't. |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 10:26 PM |
tab = {1,2,3,4,5,6}
local length
function getlength() for i,v in pairs(tab) do lenght = lenght + 1 end end
|
|
|
| Report Abuse |
|
|
Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
| |
|
|
| 17 Jul 2014 10:35 PM |
So you're saying that the user can go into the actual script and write something like this:
function add(a,b) print(a+b) end
And then you want them to be able to chat something like this and have it run
"add(4,5)"
Am I thinking about this correctly?
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 10:36 PM |
| What you are describing is impossible and never necessary unless you manually define each variable like in your original post. |
|
|
| Report Abuse |
|
|
Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
| |
|
Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
|
| 17 Jul 2014 10:40 PM |
Oh my god I got it. I called the function with the table like so:
function add(num1,num2) print(num1+num2) end
local tabble = {5,7} print(add(unpack(tabble)))
> 5 > 7 |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 10:45 PM |
Here's something you could try. When they chat a function, make sure it exists, then use loadstring to call the function, but surround it in a pcall (or ypcall if there's a wait()). If you get something like a nil value error then you can display a message saying that they're missing a variable. A fun thing about Lua is that you can supply too many arguments and it will just ignore the extraneous ones, like so:
add(1,2,3,4,5)
This will print 3, because 1+2==3, and the other three arguments are ignored.
So try something like that and see how it goes. Loadstring can be kind of finicky so have fun with that :P
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
|
| 17 Jul 2014 10:45 PM |
Oh dang, I didn't even think of that, nice job! You can ignore my previous comment then :P
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
Xsysix
|
  |
| Joined: 29 Mar 2014 |
| Total Posts: 1182 |
|
| |
|