Once again, title pretty much says it all. I have three buttons, and I want it so that when i press “Attack”, “defend” will be disabled until “Attack” returns to its blue state, and vice versa. Also, Heals can only be pressed when both are useable
function setup()
buttonTab = {
DelayButton(WIDTH/2, HEIGHT - 60, WIDTH, 50, "Attack", function() bfunc("Atk") end, 1),
DelayButton(WIDTH/2, HEIGHT - 120, WIDTH, 50, "Defend", function() bfunc("Def") end, 3),
DelayButton(WIDTH/2, HEIGHT - 180, WIDTH, 50, "Heal", function() bfunc("HP") end, 9),
}
end
function draw()
background(40, 40, 50)
for t = 1,#buttonTab do
buttonTab[t]:draw()
end
end
function touched(t)
for w = 1,#buttonTab do
buttonTab[w]:touched(t)
end
end
function bfunc(id)
print("Pressed button "..id)
if id == 1 then
buttonTab[2].canPress = false
end
end
--[[break]]--
DelayButton = class()
function DelayButton:init(x,y,w,h,name,func,delaytime)
self.x,self.y,self.w,self.h,self.name,self.func = x,y,w,h,name,func
self.c = color(255, 255, 255, 255)
self.isClicked = false
self.fs = 15
self.canPress = true
self.showline = true
self.delaytime = delaytime or 0
self.bardims = {w = self.w - 25, h = 3,r = 0,g = 127,b = 255}
color(0, 98, 255, 255)
end
function DelayButton:draw()
pushStyle()
if self.showline then
stroke(self.c)
fontSize(15)
font("AmericanTypewriter")
strokeWidth(.75)
lineCapMode(ROUND)
line(self.x-self.w/2,self.y-self.h/2,self.x-self.w/2,self.y+self.h/2)
line(self.x+self.w/2,self.y-self.h/2,self.x+self.w/2,self.y+self.h/2)
line(self.x-self.w/2+7.5,self.y-self.h/2,self.x+self.w/2-7.5,self.y-self.h/2)
line(self.x-self.w/2+7.5,self.y+self.h/2,self.x+self.w/2-7.5,self.y+self.h/2)
end
fontSize(self.fs)
fill(255)
text(self.name, self.x, self.y)
if self.isClicked then
pushStyle()
rectMode(CENTER)
fill(255)
rect(self.x,self.y,self.w + 2,self.h + 3)
fill(0)
fontSize(self.fs)
text(self.name,self.x,self.y)
popStyle()
end
rectMode(CENTER)
fill(self.bardims.r, self.bardims.g, self.bardims.b)
rect(self.x, self.y-self.h/3,self.bardims.w,self.bardims.h)
popStyle()
end
function DelayButton:touched(t)
if t.x > self.x-self.w/2 and
t.x < self.x+self.w/2 and
t.y > self.y-self.h/2 and
t.y < self.y+self.h/2 and
t.state == BEGAN and self.canPress then
self.isClicked = true
end
if t.x > self.x-self.w/2 and
t.x < self.x+self.w/2 and
t.y > self.y-self.h/2 and
t.y < self.y+self.h/2 and
t.state == ENDED and self.canPress then
self.isClicked = false
self.canPress = false
tween.delay(self.delaytime, function() self.canPress = true end)
tween(0.001, self.bardims, {w=0, r = 127, g = 127, b = 127},tween.easing.bounceIn, function()
self.func()
tween(self.delaytime, self.bardims, {w = self.w - 30}, tween.easing.quadInOut, function()
self.canPress = true
self.bardims.r = 0
self.bardims.g = 127
self.bardims.b = 255
end)
end)
end
end
function DelayButton:UpdateName(Value)
local NewName = Value
self.name = NewName
end