|
| 20 Jan 2012 03:45 PM |
Can some1 show how the MouseEnter Event should work??
Ive tried making a script with this, but it gave me an error :S |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 03:47 PM |
myGUI.MouseEnter:connect(function() print 'The mouse just roll over me ...' end)
myGUI.MouseLeave:Connect(function() print 'The mouse left me here T_T' end) |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 03:54 PM |
| And how will this work on multiple buttons @ once? |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:01 PM |
| Copy and paste it once per button, and change myGUI to the path (or variable) of each button. There are other ways, but they are more complicated and less flexible, in a way, |
|
|
| Report Abuse |
|
|
Cyrok
|
  |
| Joined: 11 Jan 2012 |
| Total Posts: 630 |
|
|
| 20 Jan 2012 04:05 PM |
guiObject.MouseEnter:connect(function(x, y) print("A mouse has entered "..guiObject.Name.." at the absolute position of "..x..", "..y) end)
ElectricAxel forgot the two arguments of the .MouseEnter event. c:
And the same goes for the .MouseLeave event (it has the x and y coordinates of the mouse's absolute position).
{ I have an OCD when it comes to non-camelCase variables/custom functions. } |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:05 PM |
well i what i have is 3 Buttons, each with a different Name.
When the mouse moves over the button, it will display the name in a TextLabel.
But i want this to be in only 1 script that works for all 3 buttons. |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:09 PM |
Cyrok I don't see how either of those parameters have any importance right now, but yes, I did forget to mention them.
Veggetoss, you can make them all work from the same script. o: Just make sure you get the Path right. |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:10 PM |
function mouseEntered() print "The mouse is on me!" end
Button1.MouseEnter:connect(mouseEntered) Button2.MouseEnter:connect(mouseEntered) Button3.MouseEnter:connect(mouseEntered) |
|
|
| Report Abuse |
|
|
Cyrok
|
  |
| Joined: 11 Jan 2012 |
| Total Posts: 630 |
|
|
| 20 Jan 2012 04:10 PM |
function mouseEnter(x, y) print("A GUI has a mouse hovering above it!") end for index, value in pairs(objectPath:GetChildren()) do -- Edit objectPath to the path to the object (must be a model) value.MouseEnter:connect(mouseEnter) end
Make sure that objectPath is set to the model of GUIs, and that those GUIs are the three GUIs you want effected.
{ I have an OCD when it comes to non-camelCase variables/custom functions. }
|
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:11 PM |
| Like I said, easy methods, lack of flexibility. |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:14 PM |
I had something before, but it didnt work:
all = script.Parent:getChildren()
function(ShowText) script.Parent.Title.Text = all.Name end
function(HideText) script.Parent.Title.Text = "" end
all.MouseEnter:connect(ShowText) all.MouseLeave:connect(HideText) |
|
|
| Report Abuse |
|
|
Cyrok
|
  |
| Joined: 11 Jan 2012 |
| Total Posts: 630 |
|
|
| 20 Jan 2012 04:15 PM |
Use my code and edit it to whatever pleases you.
{ I have an OCD when it comes to non-camelCase variables/custom functions. } |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:20 PM |
can u explain what u did?
I need to understand everything i put in my scripts, so i might be able to edit it later in the process. |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:20 PM |
@Vegget
'attempt to index field "MouseEnter" (a nil value)' Right?
It's because you're trying to connect the TABLE, not each individual object in the table. Do connect each object, you'd have to create a loop.
all = script.Parent:getChildren()
function(ShowText) script.Parent.Title.Text = all.Name end
function(HideText) script.Parent.Title.Text = "" end
for dummy, Objects in pairs(all) do if not Objects.ClassName:match("Script") then Objects.MouseEnter:connect(ShowText) Objects.MouseLeave:connect(HideText) end end |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:21 PM |
| You can actually make functions with the syntax function(name)? |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:23 PM |
I completely overlooked that. >_> I blame EA. He haxed it right before I posted!!!!
all = script.Parent:getChildren()
function ShowText() script.Parent.Title.Text = all.Name end
function HideText() script.Parent.Title.Text = "" end
for dummy, Objects in pairs(all) do if not Objects.ClassName:match("Script") then Objects.MouseEnter:connect(ShowText) Objects.MouseLeave:connect(HideText) end end |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:23 PM |
the loop i know of is this:
for i=1, #all do if all[i].ClassName = "TextButton" then
etc. |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:25 PM |
| My 1337 h4x0ring 5k331z 4r3 t00 0P f0r y0u. |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:25 PM |
| That's inefficient, and not an intended use of a numeric for loop, but it would work if you followed correct syntax for the if statement. |
|
|
| Report Abuse |
|
|
Cyrok
|
  |
| Joined: 11 Jan 2012 |
| Total Posts: 630 |
|
|
| 20 Jan 2012 04:25 PM |
function mouseEnter(x, y) print("A GUI has a mouse hovering above it!") end for index, value in pairs(objectPath:GetChildren()) do -- Edit objectPath to the path to the object (must be a model) value.MouseEnter:connect(mouseEnter) end
The first three lines is the function that will be called when the mouse is 'inside' the GUI. So if you're going to edit something, edit that (it's what will happen when any player's mouse enters one of the three GUIs).
The next three lines work like this:
for index, value in pairs(objectPath:GetChildren()) do
For that line, it's iterating through the children of an undefined variable I created (that you're supposed to edit to the path to the desired model). That means that all three of these GUIs must be children (not descendants) of a model. Here's an example:
for index, value in pairs(game:GetService("StarterGui").ScreenGui.modelName:GetChildren()) do
The next line is the line that connects our event to our custom function. I assume you've encountered this while scripting before, a connection line.
And the last line is an end to end the loop.
{ I have an OCD when it comes to non-camelCase variables/custom functions. } |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:27 PM |
| Agent, i also have a TextLabel in it, is that any problem? |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:29 PM |
| It may be a problem. Just group all of the buttons in a Frame with a size of {1,0},{1,0} under 'script.Parent' and you will be fine. Don't forget to set the BackgroundTransparency of the frame to 1 so it's invisible. |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:36 PM |
the script gives an error:
23:35:17 - Disconnected event because of exception 23:35:18 - String expected |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:38 PM |
Oh blox. >_>
all = script.Parent:getChildren()
function ShowText(TROLLOLOLOL) script.Parent.Title.Text = TROLLOLOLOL.Name end
function HideText() script.Parent.Title.Text = "" end
for dummy, Objects in pairs(all) do if not Objects.ClassName:match("Script") then Objects.MouseEnter:connect(function() ShowText(Objects) end) Objects.MouseLeave:connect(HideText) end end |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2012 04:41 PM |
It WORKS !!!!
ty so much :) |
|
|
| Report Abuse |
|
|