Codea 2.0 crashing or coding error?

Hi there, I am updating some code for a simple app that is already published and working without issue. Everytime I run it in Codea, I get kicked out of Codea as it crashes.
The only code added is an if statement with a list, though I think it works ok perhaps I should try something else? Here is the code…please let me know if I am doing something stupid?

if year == 2014 and month == 4 and day == 6 or
        year == 2014 and month == 5 and day == 14 or
        year == 2014 and month == 6 and day == 13 or 
        year == 2014 and month == 7 and day == 12 or
        year == 2014 and month == 8 and day == 10 or
        year == 2014 and month == 9 and day == 9 or
        year == 2014 and month == 10 and day == 8 or
        year == 2014 and month == 11 and day == 6 or  
        year == 2014 and month == 12 and day == 6 then
        
        fill(255, 255, 255, 104)
        ellipse(WIDTH/2,HEIGHT/2,HEIGHT-50)
end

Anyone else having issues with Codea crashing and is there a way to see what causes a crash?

For one, try putting the and’s in brackets, so (a & b & c) or (…)

Forgot to mention that Codea crashes intermittently so sometimes the code is running perfectly! The same is true if I run the original code before any updates so I don’t think it is my code afterall. The app itself still works and I am using an iPad2 - iOS 7.1
I am wondering to back up projects and reinstall Codea?

@escape75, thanks for the info - I will try out your suggestion!

@jasi I put that if statement in the draw function and let it run for awhile. I would add 1 to the day and when day reached 31 I set it to 0 and added 1 to month. I could see the ellipse anytime one of the if condition matched. I had no crashes. I think you might have a problem with your other code.

@dave1707, I understand why you suggest it’s more than likely a problem with the other code (I am certainly not a coding wiz) but then I am wondering why it never caused any issue before? Why would the app still run without problem and yet the code not run 100% of the time ok in Codea?
Here’s the free app I made more as a test to try to get into coding…

https://itunes.apple.com/nl/app/coloc/id634583570?l=en&mt=8

@jasl Your app looks nice, but I didn’t download it because that won’t do me any good. I can’t say why it doesn’t work with Codea without seeing the code and seeing what happens when it crash. But there’s nothing wrong with the above “if” statement running by itself when I ran tests with it.

@dave1707, there is one big block of code and you have helped me before (you will recognize it) which I really appreciate. I am now doubting myself and thinking the code must be a mess! (sorry for the formatting - I find it easier to read it this way without too much indentation - sacrilege I know - and obviously a couple of assets will be missing)

supportedOrientations( LANDSCAPE_ANY )

function setup()
   displayMode(FULLSCREEN)

       line1 = physics.body( EDGE,vec2(5,5),vec2(5,HEIGHT-5))
       line2 = physics.body( EDGE,vec2(WIDTH-5,5),vec2(WIDTH-5,HEIGHT-5))
       line3 = physics.body( EDGE,vec2(5,5),vec2(WIDTH-5,5))
       line4 = physics.body( EDGE,vec2(2,HEIGHT-5),vec2(WIDTH-5,HEIGHT-5))   

       cDiam = 14

       bodies = {}
       for i = 1, 24 do
       bodies[i] = physics.body( CIRCLE, cDiam)
       bodies[i].gravityScale = 0.01
       bodies[i].restitution = 1
       bodies[i].position = vec2(math.random(WIDTH), math.random(HEIGHT))
       bodies[i].linearVelocity = vec2(0,HEIGHT/2)

       c1 = physics.body( CIRCLE,cDiam)
       c1.x = math.random(WIDTH) 
       c1.y = math.random(HEIGHT) 
       c1.gravityScale = 0 
       c1.friction = 0 
       c1.linearVelocity = vec2(x1,y1)

   func = info
   end
   end

function getLocalDateTime()
   datetime = os.date("*t")
   return datetime
   end

function draw()
   func()
   end

function info()

   datetime = getLocalDateTime()
   second   = datetime.sec
   minute   = datetime.min
   hour     = datetime.hour
   year     = datetime.year
   month    = datetime.month
   day      = datetime.day
   wday     = datetime.wday

   r = hour*10.6
   g = minute*4.25
   b = second*4.25

   background(r,g,b)

   if (year == 2014 and month == 4 and day == 6) or
       (year == 2014 and month == 5 and day == 14) or
       (year == 2014 and month == 6 and day == 13) or 
       (year == 2014 and month == 7 and day == 12) or
       (year == 2014 and month == 8 and day == 10) or
       (year == 2014 and month == 9 and day == 9) or
       (year == 2014 and month == 10 and day == 8) or
       (year == 2014 and month == 11 and day == 6) or  
       (year == 2014 and month == 12 and day == 6) 
       then
       noStroke()
       fill(r,120)
       ellipse(WIDTH/2,HEIGHT/2,HEIGHT-50)
       end

   letter = math.random(33,123)
   bw = math.random(255)

   if bw >= 125 then
   bw = 255 else
   bw = 0
   end

   fontSize(56)

   w = WIDTH/2 - 200       
   eh = HEIGHT/2      
   t1 = "    "          
   text(t1,w,eh)
   w1, h1 = textSize(t1)

   w2 = WIDTH/2      
   eh2 = HEIGHT/2       
   t1 = "    "
   text(t1,w,eh)
   w1,h1=textSize(t1)

   w3 = WIDTH/2 + 200     
   eh3 = HEIGHT/2       
   t1 = "    "
   text(t1,w,eh)
   w1,h1=textSize(t1)

   if (CurrentTouch.x <= 260 and CurrentTouch.y <= HEIGHT/2) then
   font("GillSans-Light")
   fill(255, 255, 255, 255)
   stroke(255, 255, 255, 255)
   end

   if (CurrentTouch.x >= 260 and CurrentTouch.y <= HEIGHT/2) then
   font("Futura-Medium")
   fill(255, 255, 255, 255)
   stroke(255, 255, 255, 255)
   end

   if (CurrentTouch.x >= WIDTH/2 and CurrentTouch.y <= HEIGHT/2) then
   font("Baskerville")
   fill(255, 255, 255, 255)
   stroke(255, 255, 255, 255)
   end

   if (CurrentTouch.x >= 740 and CurrentTouch.y <= HEIGHT/2) then
   font("BodoniSvtyTwoITCTT-Book")
   fill(255, 255, 255, 255)
   stroke(255, 255, 255, 255)
   end

   if (CurrentTouch.x <= 260 and CurrentTouch.y >= HEIGHT/2) then
   font("GillSans-Light")
   fill(0, 0, 0, 255)
   stroke(0, 0, 0, 255)
   end

   if (CurrentTouch.x >= 260 and CurrentTouch.y >= HEIGHT/2) then
   font("Futura-Medium")
   fill(0, 0, 0, 255)
   stroke(0, 0, 0, 255)
   end

   if (CurrentTouch.x >= WIDTH/2 and CurrentTouch.y >= HEIGHT/2) then
   font("Baskerville")
   fill(0, 0, 0, 255)
   stroke(0, 0, 0, 255)
   end

   if (CurrentTouch.x >= 740 and CurrentTouch.y >= HEIGHT/2) then
   font("BodoniSvtyTwoITCTT-Book")
   fill(0, 0, 0, 255)
   stroke(0, 0, 0, 255)
   end

   if wday == 1 then 
   wday = "Sun " 
   end

   if wday == 2 then 
   wday = "Mon " 
   end

   if wday == 3 then 
   wday = "Tue "
   end

   if wday == 4 then 
   wday = "Wed " 
   end

   if wday == 5 then 
   wday = "Thu " 
   end

   if wday == 6 then 
   wday = "Fri " 
   end

   if wday == 7 then 
   wday = "Sat " 
   end

   if month == 1 then
   month = "Jan "
   end

   if month == 2 then
   month = "Feb "
   end   

   if month == 3 then
   month = "Mar "
   end

   if month == 4 then
   month = "Apr "
   end

   if month == 5 then
   month = "May "
   end

   if month == 6 then
   month = "Jun "
   end

   if month == 7 then
   month = "Jul "
   end

   if month == 8 then
   month = "Aug "
   end

   if month == 9 then
   month = "Sep "
   end

   if month == 10 then
   month = "Oct "
   end

   if month == 11 then
   month = "Nov "
   end

   if month == 12 then
   month = "Dec "
   end

   rf = math.floor(r)
   gf = math.floor(g)
   bf = math.floor(b)

   u = HEIGHT/2+220
   text(rf, WIDTH/2-200, u)
   text(gf, WIDTH/2, u)
   text(bf, WIDTH/2+200, u)

   n = HEIGHT/2+120
   text(hour, WIDTH/2-200, n)
   text(minute, WIDTH/2, n)
   text(second, WIDTH/2+200, n)

   h = HEIGHT/2 -120
   text(wday,WIDTH/2-200, h)
   text(day,WIDTH/2 -85, h)
   text(month,WIDTH/2+46, h)
   text(year,WIDTH/2+196, h)

   noFill()
   strokeWidth(1) 
   ellipse(WIDTH/2-200, HEIGHT/2, hour*5.1)
   ellipse(WIDTH/2, HEIGHT/2, minute*2)
   ellipse(WIDTH/2+200, HEIGHT/2, second*2)

   strokeWidth(2)
   rect(WIDTH/2-200, HEIGHT/2-190, 400-second*6.66, 10)
   rect(WIDTH/2-200, HEIGHT/2-215, 400-minute*6.66, 10)
   rect(WIDTH/2-200, HEIGHT/2-240, 400-hour*16.66, 10)

   sprite("Dropbox:vignette",WIDTH/2, HEIGHT/2)

   end

function touched(t)
   if t.state == BEGAN then
   if func ~= info then
   func = info
   return
   end

   if func == info then
   if (t.x>w-w1/2 and t.x<w+w1/2 and t.y>eh-h1/2 and t.y<eh+h1/2) then
   func = infoScreen
   end

   if func == info then
   if (t.x>w2-w1/2 and t.x<w2+w1/2 and t.y>eh2-h1/2 and t.y<eh2+h1/2) then
   func = fontScreen
   end

   if func == info then
   if (t.x>w3-w1/2 and t.x<w3+w1/2 and t.y>eh3-h1/2 and t.y<eh3+h1/2) then
   func = ornaScreen
   end

   end
   end
   end
   end
   end

function infoScreen()
   background(b,r,g)
   sprite("Dropbox:infoFlow",WIDTH/2, HEIGHT/2)
   sprite("Dropbox:vignette",WIDTH/2,HEIGHT/2)
   fill(255,255,255)
   font("GillSans-Light")

   u2 = HEIGHT/2+220
   text("R", WIDTH/2-200, u2)
   text("G", WIDTH/2, u2)
   text("B", WIDTH/2+200, u2)

   n2 = HEIGHT/2+120
   text("H", WIDTH/2-200, n2)
   text("M", WIDTH/2, n2)
   text("S", WIDTH/2+200, n2)

   noFill()
   strokeWidth(1)
   stroke(255,255,255)
   ellipse(WIDTH/2-200, HEIGHT/2, hour*5.1)
   ellipse(WIDTH/2, HEIGHT/2, minute*2)
   ellipse(WIDTH/2+200, HEIGHT/2, second*2)

   strokeWidth(2)
   rect(WIDTH/2-200, HEIGHT/2-190, 400-second*6.66, 10)
   rect(WIDTH/2-200, HEIGHT/2-215, 400-minute*6.66, 10)
   rect(WIDTH/2-200, HEIGHT/2-240, 400-hour*16.66, 10)
   end

function fontScreen()
   background(b,r,g)
   sprite("Dropbox:fontScreen 300 dpi 2048",WIDTH/2,HEIGHT/2,1024,768)
   sprite("Dropbox:vignette",WIDTH/2, HEIGHT/2)
   end

function ornaScreen()
   background(b,r,g)
   sprite("Dropbox:vignette",WIDTH/2, HEIGHT/2)
   font("BodoniOrnamentsITCTT") 
   fontSize(32)
   fill(bw)
   for k, v in ipairs (bodies) do
   local char = string.char(letter)
   text(char,v.x, v.y)
   end   
   end

@jasl I loaded your code and reformatted it to make it easier for me to read. It does crash every now and then, but I haven’t found a reason yet. I’ll look over the code more and let you know if I find a reason why.

@jasl Make these changes to setup() and let me know if it still crashes. Comment out the c1. lines of code.

function setup()
   displayMode(FULLSCREEN)

       line1 = physics.body( EDGE,vec2(5,5),vec2(5,HEIGHT-5))
       line2 = physics.body( EDGE,vec2(WIDTH-5,5),vec2(WIDTH-5,HEIGHT-5))
       line3 = physics.body( EDGE,vec2(5,5),vec2(WIDTH-5,5))
       line4 = physics.body( EDGE,vec2(2,HEIGHT-5),vec2(WIDTH-5,HEIGHT-5))   

       cDiam = 14

       bodies = {}
       for i = 1, 24 do
       bodies[i] = physics.body( CIRCLE, cDiam)
       bodies[i].gravityScale = 0.01
       bodies[i].restitution = 1
       bodies[i].position = vec2(math.random(WIDTH), math.random(HEIGHT))
       bodies[i].linearVelocity = vec2(0,HEIGHT/2)

       --c1 = physics.body( CIRCLE,cDiam)
       --c1.x = math.random(WIDTH) 
       --c1.y = math.random(HEIGHT) 
       --c1.gravityScale = 0 
       --c1.friction = 0 
       --c1.linearVelocity = vec2(x1,y1)

   func = info
   end
   end

@dave1707 - Thanks! No longer crashing… That was kind of embarrassing :-/ I learned a few things here though and that’s good. Some of them being not to copy paste code from unfinished projects, to look for potential doubling in the code that makes no sense whatsoever and that I am clearly indebted to you.

I have no idea if you like beer but I’d definitely buy you a few any day!

@jasl That’s the next step in programming, trying to figure out why code crashes. Once you get comfortable with programming, you can start learning why code doesn’t work as expected and how to track it down.