• IsHovered() Returning true and false?
    2 replies, posted
So I'm trying to get a sound to play once when the mouse hovers over a button and I found something interesting. The way I was gonna do it was have a counter, and play the sound on the first initial frame. Only one problem, I can't reset the counter when the mouse leaves the frame because seemingly Panel:IsHovered() is returning true [I]and[/I] false every frame or every other frame? Here's my code (gutted) [CODE]local count = 0 function drawButton(self, w, h) .. code .. -- this all works well but it will only play once on the initial hover and not on following hovers if (self:IsHovered()) then count = count + 1 .. code .. if (count == 1) then surface.PlaySound("file") end -- this should allow it to play on additional hovers but it just stops sound from playing at all else -- if its not hovered just set to 0? Should work right? count = 0 end print(self:IsHovered()) end[/CODE] [url]https://gyazo.com/684963cfe0134476798b2ace161cad5f[/url] (gif) i threw in the print(self:IsHovered()) to see what was going on and this is what printed out [IMG]https://i.gyazo.com/a5d7b37dbf94c8f7371b5c4a2f08d58c.png[/IMG]
Are you using drawButton with multiple buttons? Also, you may want to try self.Hovered, but it's probably the same
Well, just found [URL="http://wiki.garrysmod.com/page/PANEL/OnCursorEntered"]this[/URL]... But I still don't get why IsHovered() is returning like that [editline]25th May 2017[/editline] [QUOTE=MPan1;52276188]Are you using drawButton with multiple buttons? Also, you may want to try self.Hovered, but it's probably the same[/QUOTE] And yeah, I am using it with multiple buttons [editline]25th May 2017[/editline] Oh wow, that's why. Lol.. I'm in hovering one but not the other.. Thanks haha.
Sorry, you need to Log In to post a reply to this thread.