I have a game where you drag a card to pile to end your turn, but once I touch the card it freezes until I release (I know this because my frames per second monitor froze up, and when I tried to record it, the timer on the recorder froze up). I’m willing to PM my code, but does anyone know what might be causing this
@Doge I’ve had this, it could be what @ignatz suggested or it could be that you’re trying to use setContext with too many processes inside it (I’ve know that to freeze up when in the touched function), if that is the case try moving it to the draw function.
That might be the issue @Luatee. I’m using ignatz’ working with playing cards (with my own modifications) which does have a lot of processes. Here’s my touch function:
function Cards:touched(touch)
local tch = vec2(touch.x,touch.y)
cardPos = {}
inserted = false
for i=1,7 do
cardPos[i] = vec2(i*gap,100)
end
if touch.state==ENDED then
if tch:dist(pilePos)<50 and not self.pickedup then
self:switchPiles(self.drawP,self.userCards.hand,#self.drawP,self.drawP[#self.drawP])
self.pickedup = true
--self:updateSel()
end
--[[
for x,a in pairs(cardPos) do
if tch:dist(a)<80 then
if self.userCards.hand[x].sel~=true then
self.userCards.hand[x].sel = true
if self.pickedup and not inserted then
inserted=true
b[#b+1]=Button(cardPos[x].x,cardPos[x].y+200,"Discard",
function() discard() end)
--inserted=true
end
else
self.userCards.hand[x].sel = false
table.remove()
end
end
end
for a,x in pairs(self.userCards.hand) do
if x.sel==true then
if card.pickedup then
end
end
end
--]]
end
if touch.state==MOVING then
for x,y in pairs(self.userCards.hand) do
print(y.pos)
if tch:dist(y.pos)<80 then
y.pos = tch
end
end
end
end
Move what to the draw function? The touch or the setContext()?
@Doge - first, I notice you have a line table.remove()
with nothing in the brackets, which is an error. I would fix this.
Second, I would try commenting out some of the chunks in there, eg the for loops and if statements. I would in fact start by commenting out everything in the touched function, and then gradually uncommenting a bit at a time, until the program freezes. Then you know which bit is causing the problem.
That part of the code is commented out and I just realized my issue. I was printing something if the state is moving… sigh once again I overanalyzed. Thanks for help anyway. @Luatee and @Ignatz
most likely an endless loop