Overkillz Posted May 23, 2016 Posted May 23, 2016 Hey dear guys, Im having a problem building a Lib, well, my idea is to create a rectangle which when the mouse is over it, the alpha increase only to it. Well, its a system to create animate buttons local sX,sY = guiGetScreenSize() function animB(posX,posY,sizeX,sizeY,r,g,b) if isCursorHover(posX,posY,sizeX,sizeY) then aFinal = math.min(aFinal + 20, 255) dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) else aFinal = math.min(aFinal - 20, 0) dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) end end function isCursorHover(posX,posY,sizeX,sizeY) local x,y = 0,0 if isCursorShowing() then x,y = getCursorPosition() x,y = sX*x,sY*y else return false end if x>=posX and x<=posX+sizeX and y>=posY and y<=posY+sizeY then return true else return false end end -- ## LETS TEST IT function testingIt() animB(500,500,270,40,255,255,255) end addEventHandler("onClientRender",getRootElement(),testingIt) Well, the error that I get on Debugscript 3 is: attemt to perfom arithmetic on global 'aFinal' (a nil value) I hope u can tell me how can I define it Regards.
ViRuZGamiing Posted May 23, 2016 Posted May 23, 2016 can't you just add this on line 2: local aFinal = 0
Overkillz Posted May 23, 2016 Author Posted May 23, 2016 Ye, I know it, but if I add more than one element, like this animB(800,500,270,40,255,255,255) animB(800,700,270,40,255,255,255) animB(300,700,270,40,255,255,255) The animation doesn't work.
ViRuZGamiing Posted May 23, 2016 Posted May 23, 2016 Not 100% but I think you can do: if (aFinal == nil) then aFinal = 0 end tested in LUA Demo
Overkillz Posted May 23, 2016 Author Posted May 23, 2016 I didnt get u, whats the goal of mark the alpha as nil.
ViRuZGamiing Posted May 23, 2016 Posted May 23, 2016 then you can declare the alpha as 0 the first time. function animB(posX,posY,sizeX,sizeY,r,g,b) if (aFinal == nil) then aFinal = 0 end if isCursorHover(posX,posY,sizeX,sizeY) then aFinal = math.min(aFinal + 20, 255) dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) else aFinal = math.min(aFinal - 20, 0) dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) end end
Moderators IIYAMA Posted May 24, 2016 Moderators Posted May 24, 2016 There is also math.max (another problem) else aFinal = math.min(aFinal - 20, 0) dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) end else aFinal = math.max(aFinal - 20, 0) dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) end
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now