Project issues

local menu = true
local play = false 
local how = false
--
function CurrentTouch (touch)
    local a = CurrentTouch.x
    local b = CurrentTouch.y
----
   if a>455 and a<575 and b>420 and b<480 then
        local play = true
        local menu = false
        local how = false
----
   elseif a>460 and a<575 and b>360 and b<420 then
        local how = true
        local play = false
        local menu = false 
    end
end

----

if (menu = true) then
    function draw()
        background(38, 47, 61, 255)       
        --Play--
        fill(255, 255, 255, 255)
        rect(460,420,120,60)
        fill(0, 0, 0, 255)
        font("AmericanTypewriter-Bold")
        fontSize(20)
        text("Play",520,453)
        --How To--
        fill(255, 255, 255, 255)
        rect(460,360,120,60)
        fill(0, 0, 0, 255)
        font("AmericanTypewriter-Bold")
        fontSize(20)
        text("How To",520,393)
        --Title--
        fill(255, 255, 255, 255)
        font("Futura-CondensedExtraBold")
        fontSize(155)
        text("Burgular",520,585)
        fill(0, 156, 255, 255)
        font("Futura-CondensedExtraBold")
        fontSize(150)
        text("Burgular",520,585)
    end
end     --AAA

----
    elseif (play = true) then
        function draw()
            background(38, 47, 61, 255)         
        end 
----
    elseif (how = true) then
        function draw()
            background(38, 47, 61, 255)
            rect(20,20,20,20)
        end
    end
end

--(IGNORE THIS) elseif a>500 and a<537 and b>97 and b<167 then--

If anyone can find the flaw then that would be greatly apprieciated… thx

@bhob12 - put three ~ before and after your code to make it look nice. I did it for you above.

@bhob12 - the error is probably an extra “end”, where I have put AAA in your code above.

But instead of including the draw function in your if test, you should do it the other way round, ie

function draw()
    if menu ==true then
        --code
    elseif code==true then
        --code
   end
end

@bhob12 You have 3 function draw(). You only need 1. Your if statements aren’t written correctly. You don’t need all those locals. See the code below that I adjusted.


displayMode(FULLSCREEN)

function setup()
    menu = true
    play = false
    how = false
    a=0
    b=0
end

function draw()
    if a>455 and a<575 and b>420 and b<480 then
        play = true
        menu = false
        how = false
    elseif a>460 and a<575 and b>360 and b<420 then
        how = true
        play = false
        menu = false 
    end
    if menu == true then
        background(38, 47, 61, 255)
        --Play--
        fill(255, 255, 255, 255)
        rect(460,420,120,60)
        fill(0, 0, 0, 255)
        font("AmericanTypewriter-Bold")
        fontSize(20)
        text("Play",520,453)
        --How To--
        fill(255, 255, 255, 255)
        rect(460,360,120,60)
        fill(0, 0, 0, 255)
        font("AmericanTypewriter-Bold")
        fontSize(20)
        text("How To",520,393)
        --Title--
        fill(255, 255, 255, 255)
        font("Futura-CondensedExtraBold")
        fontSize(155)
        text("Burgular",520,585)
        fill(0, 156, 255, 255)
        font("Futura-CondensedExtraBold")
        fontSize(150)
        text("Burgular",520,585)
    elseif play== true then
        background(38, 47, 61, 255)
    elseif how == true then
        background(38, 47, 61, 255)
        rect(20,20,20,20)
    end
end

function touched(t)
    if t.state==BEGAN then
        a=t.x
        b=t.y
    end
end

I’m sorry, but there is so much wrong with that code. That would barely work in Codea.

function setup()
    menu = true
    play = false 
    how = false
end

function draw()
    background(38, 47, 61)
    if menu then
        fill(255)
        rect(460, 420, 120, 60)
        fill(0)
        font("AmericanTypewriter-Bold")
        fontSize(20)
        text("Play", 520, 453)
        fill(255)
        rect(460, 360, 120, 60)
        fill(0)
        text("How To", 520, 393)
        fill(255)
        fontSize(155)
        font("Futura-CondensedExtraBold")
        text("Burgular", 520, 585)
        fill(0, 156, 255)
        fontSize(150)
        text("Burgular", 520, 585)
    elseif play then
        -- Play code here
    elseif how then
        rect(20,20,20,20)
    end
end

function touched(touch)
    local a = touch.x
    local b = touch.y
    if a>455 and a<575 and b>420 and b<480 then
        play = true
        menu = false
        how = false
   elseif a>460 and a<575 and b>360 and b<420 then
        how = true
        play = false
        menu = false 
    end
end


I think I fixed everything, corrected syntax, order, spacing, locals, etc. Works fine now.

For future reference, please don’t go to the Codea Forums giving us a bunch of code and saying “fix it.”

Edit: Welcome to the Codea Forums!

Wow thank you all very much i REALLY appreciate the help… I’m trying to teach myself how to code… Anyways thanks a lot!

Where do I go to ask about code problems?

@bhob12 - I suggest you ask all your questions in this thread, to keep the forum neat. If you want to change the title, just edit the first post at the top.

Put three ~ before and after your code to make it look nice. If you go back and edit your first post, you will see how I did it for you.

Thank you

Also how do I comment so the code is neat and not paragraph looking?

How do I delay a function

function setup()
local x = math.random(#,#)
local y = math.random(#,#)
end
function draw()
     repeat
---Delay---
          ellipse(x,y,100,100)
     until 2>3
end

Then how do I delay that for say 15 seconds?

@bhob12 - search the forum for “timer”, you’ll find several examples

Thanks

local speed = 1
local sped = 10
local y = 900
function draw()
       if timer < 300 then
            background(233, 20, 20, 255)
            fill(65, 165, 224, 255)
            ellipse(300,y,50,50) 
            y = y - speed 
       elseif timer >300 then
            background(233, 20, 20, 255)
            fill(65, 165, 224, 255)
            ellipse(300,y,50,50) 
            y = y - sped 
        end
    end

Ok so I have used the timer a little bit but I’m confused on this

@bhob12 You can also use tween.delay(time,callback) to delay a function call. I’m not sure what you are trying to do with your above code. There is no setup function and timer is not declared anywhere. Also, What happens when the timer is at 300? might want to use a >=300 instead of >300.

tween.delay(15,function() print("Hello World") end)

@bhob12 Actually a better way to do your “if” statement is to use an “if” “else”. See your code below.


local speed = 1
local sped = 10
local y = 900
function draw()
       if timer < 300 then
            background(233, 20, 20, 255)
            fill(65, 165, 224, 255)
            ellipse(300,y,50,50) 
            y = y - speed 
       else
            background(233, 20, 20, 255)
            fill(65, 165, 224, 255)
            ellipse(300,y,50,50) 
            y = y - sped 
        end
end

Ok thanks for now :slight_smile:

tween.delay(15,function() print("Hello World") end)
tween.delay(15,function() print("Hello World") end)

Ok so say I wanna do it twice… How?
delete end maybe? Idk