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 » Scripting Helpers
Home Search
 

Re: How would I do this?

Previous Thread :: Next Thread 
Xsysix is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. 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
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
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 is not online. Xsysix
Joined: 29 Mar 2014
Total Posts: 1182
17 Jul 2014 10:29 PM
No thats not what I need
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
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 is not online. Xsysix
Joined: 29 Mar 2014
Total Posts: 1182
17 Jul 2014 10:37 PM
Exactly @swimguy
Report Abuse
Xsysix is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. Xsysix
Joined: 29 Mar 2014
Total Posts: 1182
17 Jul 2014 10:48 PM
Thanks for all the help.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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