soutenuJoin Date: 2011-12-09 Post Count: 1021 |
function tmp(guiobj)
return function() guiobj.BackgroundColor3 = Color3.new(1,1,1) end
end
obj1.MouseEnter:Connect(tmp(obj1))
obj2.MouseEnter:Connect(tmp(obj2))
obj3.MouseEnter:Connect(tmp(obj3))
...etc |
|
|
I believe you can loop through the GUI objects and call it from there:
for index, obj in pairs(objectPaths) do
obj.MouseEnter:connect(tmp(obj))
end |
|
soutenuJoin Date: 2011-12-09 Post Count: 1021 |
@Knightmare not the connecting part, im mainly concerned with the function |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Sadly there's not. You can't pass extra arguments to Connect and have it forward to your callback (there's a few reasons I can think of why, but that's not really relevant).
|
|
soutenuJoin Date: 2011-12-09 Post Count: 1021 |
#### alright thanks, ill keep that in mind |
|
|
I'm not sure what you're trying to do. Whenever the mouse hovers over a guiobject, you want to change the background to white? I'm not sure why you're returning anything, and what "efficient" in this case would be. |
|
|
soutenuJoin Date: 2011-12-09 Post Count: 1021 |
@Knight im asking if that's the most efficient way of writing a function once compared to having something like this,
obj1.MouseEnter:Connect(function()
--body
end)
obj2.MouseEnter:Connect(function()
--body
end) |
|
|
If they have the same body then you could loop through the objects and call it from there. I wasn't sure about the connection, so I'll regard ### in that case. |
|
Lucas_LuaJoin Date: 2008-06-18 Post Count: 7521 |
There's no way to make this more efficient, but you can pass anonymous functions instead:
for _, obj in pairs(LIST_OF_OBJECTS) do
obj.MouseEnter:connect(function() obj.BackgroundColor3 = Color3.new(1, 1, 1) end);
end
This is what you are doing anyway, except this frees up a name in the namespace. Not much of an improvement, but it is more readable. |
|
soutenuJoin Date: 2011-12-09 Post Count: 1021 |
this is nice since i can just edit the body of the function returned rather than editing every single body if i want to make a change to the function |
|
soutenuJoin Date: 2011-12-09 Post Count: 1021 |
not all of my items in the list would work since some of them i don't want to react to MoverHover |
|
soutenuJoin Date: 2011-12-09 Post Count: 1021 |
Enter*** |
|
|
Then set a condition for the objects you do want to trigger. |
|
soutenuJoin Date: 2011-12-09 Post Count: 1021 |
so i feel like what im doing would be better and shorter than iterating through an array and having an ignorelist |
|