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: Can I do this?

Previous Thread :: Next Thread 
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 11:59 AM
function connect(event, func)
event:connect(func)
end

connect(game.Workspace.Part.Touched, function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") and game.Players[hit.Parent.Name] then
hit.Parent:BreakJoints()
end
end)




Like, is there a problem doing event:connect in the function? Or do I have to manually add the events in the function itself?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
17 Jan 2015 12:13 PM
No, there isn't a problem with that. Connect is a member of event, so event.connect gets it directly from event.

But let me give you something interesting.

connect = game.ChildAdded.connect


There, I just shortened your three lines into one line. It works the exact same way.
connect(event, func)
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 12:21 PM
Alright, good.

But like, it's not shortened because I would need to change the event in the variable and stuff...
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Jan 2015 12:34 PM
When you call Event:connect(...) you're actually calling Event.connect(Event,...) which is the same as what you just set up. Meaning that what Jarod said is actually more efficient ^^
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 12:35 PM
Alright I get it.

I get I can do it as a variable but I wanna use a function to specify which event to use.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
17 Jan 2015 12:36 PM
so game.ChildAdded.connect actually works for any event, not just ChildAdded.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
17 Jan 2015 12:36 PM
You do specify which event. My example is used exactly the same as your function is.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 12:47 PM
connect = game.ChildAdded.connect


connect(workspace.Part.Touched, function(hit)
--dostuff
end)


now how is that supposed to work
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Jan 2015 12:57 PM
The same way as you tried the other one

function connect(event, func)
event:connect(func)
end

Is like, an inefficient way of going

Event.connect(event, func)

So, you know, you should go look at tables some more.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 12:59 PM
what has tables got to do with this

seriously im confused

can someone explain



....

Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 01:02 PM
http://wiki.roblox.com/index.php?title=RBXScriptSignal

connect is a method, why do you guys talk of it as not a method
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
17 Jan 2015 01:08 PM
Methods are still members, accessed with a .

Syntactic sugar allows you the easier option of using :


You'll understand it more if you get into OOP.
Oh wait, you said that in a message earlier. Fine, I'll explain.

Table = {
      ExampleFunction = function(Self, ...) print(Self.Value) end,
      Value = 235898
}

ExampleFunction has the self argument, because it is a member of a table.

Table.ExampleFunction(Table, ...)
is the same as
Table:ExampleFunction(...)

With a colon, it automatically gives the self argument.
With a period (Without the syntactic sugar) you need to provide the self argument.

The second one, the period, is faster. Something like it doesn't need to locate the table of which's method you're calling, or something.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 01:15 PM
Oh, I see.

You two thought I knew a lot less than I already know. Okay I will explain.

I know how tables work, I said

connect = game.ChildAdded.connect


connect(workspace.Part.Touched, function(hit)
--dostuff
end)


Thats the same as

game.ChildAdded.connect(workspace.Part.Touched, function(hit)
--dostuff
end)

How is that supposed to work!

What has childadded got to do with any of this. And doesen't connect only require a function argument? There two in there.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
17 Jan 2015 01:18 PM
RBXScriptSignal.Connect is a function which accesses the passed RBXScriptSignal and a function.

game.ChildAdded:connect(function() end) == game.ChildAdded.connect(game.ChildAdded, function() end)
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Jan 2015 01:19 PM
Guess what childAdded is? It's a RBXScriptSignal (Or event or whatever its classname is), and guess what that means? It means that its methods can be used like any other. It's like going

local connect = RBXScriptSignal.connect;

But since you can't directly reference the event class, you have to take an example one

local connect = game.ChildAdded.connect;

Okay?
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 01:19 PM
I don't even wanna know...
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
17 Jan 2015 01:20 PM
good job for refusing to learn
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 01:21 PM
np
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
17 Jan 2015 01:22 PM
Well since all Events have the same properties and methods, just use game.ChildAdded as the event, but use a different 'self' argument.

You can do this the same way.

game.Destroy(workspace.BasePlate)
Report Abuse
Argelius is not online. Argelius
Joined: 19 Jul 2010
Total Posts: 4047
17 Jan 2015 01:28 PM
So do you mean

connect = game.ChildAdded.connect

is the same as

connect = game.Players.PlayerAdded.connect
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Jan 2015 01:36 PM
Yeah. Infact, you should be able to do an equality check on them and have it return true in theory.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
17 Jan 2015 01:41 PM
Are you sure that will be true? Let me check. (Why to I often tell someone to wait while I check but then post it all at once?)

False.

That would be like saying
workspace.BasePlate == Instance.new("Part")
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
17 Jan 2015 01:41 PM
Oh wait. This is connect, not the event. *Rolls eyes*
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
17 Jan 2015 01:43 PM
print(game.ChildAdded.connect == workspace.ChildAdded.connect)
--> False


That doesn't mean it won't work the way we said above. It will work that way, even though they aren't both properties of the same event.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Jan 2015 02:17 PM
I mean I get it..I just think that's so dumb...
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