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: Multiple args in global functions

Previous Thread :: Next Thread 
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
24 Jun 2013 05:32 PM
My code:

_G.split = function(str, pat)
local t = {}
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = string.find(str, fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t, cap)
end
last_end = e+1
s, e, cap = string.find(str, fpat, last_end)
end
if last_end <= #str then
cap = string.sub(str, last_end)
table.insert(t, cap)
end
return t
end

local t = _G.split("d", "edrdpderp")
for _,v in pairs(t) do
print(v)
end

It acts as if "Pat" is nil, instead of "edrdpderp" like it should be.
I'm new to _G, but I would like to know how you can put more than one arg in a global function.

Emerson wrote an essay on that
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
24 Jun 2013 05:34 PM
you can have almost infinite arguments.
dont remember the name for it but technically:

function asd(...)
local arguments = {}
for i =1, #arguments do
print(arguments[i])
end
end

asd(1,3,3,5,35,35,35,3,46,5,64,646,45,654,765,65,6,5,4,64,65,46,5,64,6,3,45)

also works with global functions.


There would be an error in your code.
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
24 Jun 2013 05:35 PM
*

function asd(...)
local arguments = {...}
for i =1, #arguments do
print(arguments[i])
end
end
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
24 Jun 2013 05:38 PM
I tried that, but it still thinks there's only one arg.

Emerson wrote an essay on that
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
24 Jun 2013 05:40 PM
changing
_G.split= function(str,pat)
to
function _G.split(str,pat)
still did the same thing qq.

Emerson wrote an essay on that
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
24 Jun 2013 05:40 PM
My code as a global function worked fine.
"_G.asd(1,1,31,2,3,4,234,23,23,525,235,23,4,5435,4)"
returned:
1
1
31
2
3
4
234
23
23
525
235
23
4
5435
4
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
24 Jun 2013 05:41 PM
Must be my split function. This is the exact split function on the lua wiki though.

Emerson wrote an essay on that
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
24 Jun 2013 05:42 PM
try adding

print(tostring(pat))

before you add it to the string and tell me does it print nil
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
24 Jun 2013 05:44 PM
I MIGHT HAVE FOUND A SOLUTION, I AM STUPID SORRY.


_G is a table.

Tables require a "self" argument before your own args.

like this:

table = {}

function table.func(self,arg)
print(arg)
end

table.func("asd")

would print asd.


Not sure if this is with _G
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
24 Jun 2013 05:45 PM
What it's doing is returning str.

Emerson wrote an essay on that
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
24 Jun 2013 05:46 PM
Oh, and it's not _G.
I was just being stupid and not testing it as a normal function.

Emerson wrote an essay on that
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
24 Jun 2013 05:58 PM
I reposted, since the problem is really something else.

Emerson wrote an essay on that
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