I NEED HELP (pls)

@Killer.Jo - I think you need to step away from coding and think about what it is you want to introduce into your project. Write down all the features. Then you can describe what you want your project to do in the forum.

If you are trying to reproduce a game then just point us to an example.

Give me a little time

If I’m REALLY REALLY good, I’ll do it as a game and publish a lot, maybe also:

A start menu, with many buttons (with start button) when you click on it, so which levels that drove you out of boredom (e.g. a fairly light supermarket simulator) and even further. There is a shop (by the way: it should be 2D) and even further (this should also come with updates)

@Killer.Jo - OK, so looking at this from the outside you would probably need a splash screen (most games do), an intro screen which describes the object records your name (nickname) and explains the objectives and scoring system, the game screen (whatever you have in mind) and finally the hi-score screen to record achievements and possibly gets your name (nickname).

Three of these are relatively easy and then there’s the game screen.

I hope your good with graphics, there are a lot in Codea, but that depends on what you are planning on the game itself.

I would start with those three which would allow you to pick up the basics of Codea and tackle the more difficult game screen last.

Okay, then ill do that

Uhh, I need a little help… if you solve the problem, then I am ultimate grateful to you :smiling_face_with_tear: so if I create a touch (button) and when you click on the touch on it comes, e.g. a new background, but if you click on the touch again, the touch is still there but it should disappear because otherwise it is not a button

@Killer.Jo - OK, post your code and I’ll play around with it.


-- That's an example, so a very very small code


function draw()
    
    background(28)
    button = readImage(asset.builtin.UI.Blue_Button_04)
    txt9 = "Ronaldo"
    
    text(txt9, 550, 500)
    sprite(button, 550, 500)
    
    if CurrentTouch.state == ENDED and CurrentTouch.x >= 450 and CurrentTouch.x <= 600 and CurrentTouch.y >= 450 and CurrentTouch.y <= 600 then
        sprite(asset.builtin.UI.Blue_Button_05, 550, 500)
        background(255)
    end
end

So in this example is a button, if you click on it then another background comes. But when you click on it, the touch is still there, but it should ā€œgo awayā€ when you click on it (the touch so the if)

@Killer.Jo - just think about the demo with the buttons I posted. For the moment don’t use CurrentTouch - use the function touched(t) function to capture touches to the screen. Also you have definitions in Draw() that should be defined once not every time you run Draw(). Changing values in Draw() is OK to establish change but use Setup() to initialise them.
At an early stage of learning set up your project with Seup(), Draw() and Touched() in.

I’ll try to do this on my PC now so I don’t know how it will run - here goes:


function setup()
    --
    txt9 = "Ronaldo"
    txt10 = "I am scrn 2 !"
    scrn = "first"
end

function draw()
    -- 
    if scrn == "first" then
        background(118, 171, 226)
    else
        background(76, 255, 0)
        scrn = txt10
    end
    fill(255, 0, 13)
    fontSize(32)
    font("Arial-BoldItalicMT")
    text(txt10,500,500)

end

function touched(t)
    --
    if t.state == ENDED then
        if t.pos.x >= 450 and t.pos.x <= 600 then
            if t.pos.y >= 450 and t.pos.y <= 600 then
                if scrn == "first" then
                    scrn = txt10
                else
                    scrn = "first"
                end
            end
        end
    end
end

Edit: Mistakes in first stab at this, trying to run something in parallel. Is this OK ?

Edit: posted up working as I thought you wanted.

So actually I wanted when you click on the button that the ā€œbutton touchā€ ā€œgoes awayā€ so I mean that you can no longer touch the button and that the background does not ā€œdisappearā€ when you touch something. That would be super super super super nice of you.

@Killer.Jo - here it is , I hope. You only needed to eliminate the switch back in the touched() function.

function setup()
    --
    txt9 = "Ronaldo"
    txt10 = "I am scrn 2 !"
    scrn = "first"
end

function draw()
    -- 
    if scrn == "first" then
        background(118, 171, 226)
    else
        background(76, 255, 0)
        scrn = txt10
    end
    fill(255, 0, 13)
    fontSize(32)
    font("Arial-BoldItalicMT")
    text(txt10,500,500)
end

function touched(t)
    --
    if t.state == ENDED then
        if t.pos.x >= 450 and t.pos.x <= 600 then
            if t.pos.y >= 450 and t.pos.y <= 600 then
                if scrn == "first" then
                    scrn = txt10
                end
            end
        end
    end
end

Thankssss!!! My problem is solved!!


function setup()
    --
    txt9 = "Ronaldo"
    txt10 = "Zum starten auf diesen Text klicken !"
    scrn = "first"
    r = ""
    scrn1 = "first1"
    r1 = "1"
end

function draw()
    -- 
    if scrn == "first" then
        background(118, 171, 226) 
    else
        background(76, 255, 0)
        text("Was ist besonders an deinen Noten?", 550, 300)
        
    end
    if scrn1 == "first1" then
        background(118, 171, 226)
        background(0, 96, 255)
        text("Was ist besonders an deinen Noten?", 550, 300)
        
    end
    fill(255, 0, 13)
    fontSize(32)
    font("Arial-BoldItalicMT")
    text(txt10, 550, 500)
end
function touched(t)
    --
    if t.state == ENDED then
        if t.pos.x >= 450 and t.pos.x <= 600 then
            if t.pos.y >= 450 and t.pos.y <= 600 then
                if scrn == "first" then
                    scrn = r
                end
            end
        end
    end
    
    if t.state == ENDED then
        if t.pos.x >= 500 and t.pos.x <= 350 then
            if t.pos.y >= 500 and t.pos.y <= 350 then
                if scrn1 == "first1" then
                    scrn1 = r1
end
end end end end 

I tried to create a second button. Unfortunately, that didn’t work out so well, if you can solve the problem I would be very happy… edit: if you solve it, then you can also do that if you click on the button with the text ā€œClick on this text to startā€ that the second button appears? And how do I keep doing it (so if you click the 2nd button you can click the 3rd button and so on. I hope you manage to explain and ā€œdoā€ it​:sweat_smile::smiling_face_with_tear:)?

@Killer.Jo - I’ve played around with this, retained the text as a button and threw a few tidying up in, unused code is remarked out but still present. Hope this helps.


viewer.mode = FULLSCREEN
function setup()
    --
    midX, midY = WIDTH//2, HEIGHT//2
  --  txt9 = "Ronaldo"
 --   txt10 = ""
    scrn = "first"
 --   r = ""
 --   r1 = "1"
    scrn1 = "first1"
    scrn2 = "second"
    scrn3 = "third"
    scrn4 = "fourth"
    language = "german"
    intro1G = "Zum starten auf diesen Text klicken !"
    intro1E = "Click on this text to start !"
    intro = ""
    question1G = "Was ist besonders an deinen Noten?"
    question1E = "What is so special about your grades?"
    question = ""
    language = "german"
   -- language = "english"
end

function draw()
    -- 
    if scrn == "first" then
        background(118, 171, 226) 
    elseif scrn == "second" then
        background(255, 255, 0)
    elseif scrn == "third" then
        background(255, 135, 0)
    elseif scrn == "fourth" then
        background(255, 0, 19)
    end
    textMode(CENTER)
    fill(0)
    fontSize(32)
    font("Georgia-Bold")
    if language == "german" then
        intro = intro1G
        question = question1G
    elseif language == "english" then
        intro = intro1E
        question = question1E
    end
    text(intro, midX, midY)
    text(question,midX, midY-64)
end

function touched(t)
    --
    if t.state == ENDED then
        testX, testY = math.abs(midX - t.pos.x), math.abs(midY - t.pos.y)
        print(testX,testY)
        if testX <= 200 and testY <= 100 then
            if scrn == "first" then
                scrn = "second"
            elseif scrn == "second" then
                scrn = "third"
            elseif scrn == "third" then
                scrn = "fourth"
            end
        end
    end
end 

I’m going to copy and ā€œextendā€ the code now… By the way: this: What’s so special about your grades I was for fun, no idea just had no ideasšŸ˜‚

I have one of my 1000 questions: the first code you sent me, with the code we can solve my problem. And that is the part of the code:

ˋˋfunction touched(t) -- if t.state == BEGAN then var = "Taaaaraaaah!!!!" end end ˋˋ

Can you edit it so that the touch(t) is at a location?

Edit: only a background and the touch

@Killer.Jo - just been playing around with Codea Aircode 2 on my Mac and put this code in with that, but having trouble transferring it too my iPad to check so I’m posting it up as when I thought it would work. Tap in the circle. You should have been able to sort this out from the previous examples. Also you should only get a verbal message of tarah ! from this as it is just to demonstrate the touch.


-- Killer.Jo Latest

function setup()
    --
    midX, midY = WIDTH//2, HEIGHT//2
    loc = vec2(midX, midY)
    rads = 100
    txt = ""
end

function draw()
    -- 
    background(118, 171, 226) 
    ellipseMode(CENTER)
    stroke(255,255,255)
    strokeWidth(8)
    ellipse(midX, midY, 200,200)
end

function touched(t)
    --
    if t.state == ENDED then
        if inCircle(t.pos, loc, rads ) then
            txt = "Taaaaraaah !!!!"
        else
            txt = ""
        end
        print(txt)
    end
end 


function inCircle(p, c, r)    
    -- p is the point, c is the center of the circle, and r is the radius
    local dist = math.sqrt((p.x - c.x)^2 + (p.y - c.y)^2)
    if dist < rads then return true else return false end
end


I’ll get it onto my iPad and test it but it coould take me a little time.

Edit: made a couple of changes please check.

Edit: couple more changes now working OK.

Ok ill copy it

Siuu!

Edit: I just copied the code, I didn’t read it. Now I’ve read it, I’m sorry. You can already notice a few mistakes :upside_down_face: could solve one…

@Killer.Jo - no reply, did it give you what you needed.

@Killer.Jo Since you’re messing with menu’s, here’s a small menu program I have that lets you add/execute code in as many different screens as you want. It’s set up for 5 right now.

viewer.mode=FULLSCREEN

function setup()
    ang=0
    fx,fv=15,5
    show=false
    fOffset=0
    sel={{"Func1",func1},
         {"Func2",func2},
         {"Func3",func3},
         {"Func4",func4},
         {"Func5",func5},
         {"Back to editor",exit},}
end

function draw()
    background(62)
    fill(255)
    if show then
        showSelection()
    else
        fill(255)
        text("Double tap screen for MENU",WIDTH/2,HEIGHT/2)
    end
    if fOffset>0 then
        sel[fOffset][2]()
    end
end

function showSelection()
    rectMode(CENTER)
    stroke(0, 237, 255, 255)
    strokeWidth(3)
    fill(255, 254, 0, 200)
    rect(shx,shy,150,40)
    fill(255, 0, 0, 255)
    text("Select a Function",shx,shy)
    for z=1,#sel do
        fill(47, 207, 122, 109)
        rect(shx,shy-z*40,150,40)
        fill(255)
        text(sel[z][1],shx,shy-z*40)
    end
end

function touched(t)
   if t.state==BEGAN then
        if t.tapCount==2 then
            fOffset=0
            shx=WIDTH/2
            shy=HEIGHT/1.4
            show=true
            return
        end
        if show and t.x>shx-75 and t.x<shx+75 then
            for z=1,#sel do
                if t.y>shy-z*40-15 and t.y<shy-z*40+15 then
                    fOffset=z
                    show=false
                    return
                end
            end
        end
    end
end

function exit()
    viewer.close()
end

function func1()
    background(236, 187, 67)
    fill(255,0,0)
    text("Double tap screen for MENU",WIDTH/2,HEIGHT-100)
    text("Executing func1",WIDTH/2,HEIGHT-130)
    fill(53, 0, 255)
    ellipse(fx,HEIGHT/2,100)
    fx=fx+fv
    if fx>=WIDTH-10 or fx<=10 then
        fv=fv*-1
    end
end

function func2()
    background(58, 255, 0)
    fill(255,0,0)
    text("Double tap screen for MENU",WIDTH/2,HEIGHT-100)
    text("Executing func2",WIDTH/2,HEIGHT-130)
    translate(WIDTH/2,HEIGHT/2)
    ang=ang+1
    rotate(ang)
    rect(0,0,150,250)
end

function func3()
    background(58, 255, 0)
    fill(255,0,0)
    text("Double tap screen for MENU",WIDTH/2,HEIGHT-100)
    text("Executing func3",WIDTH/2,HEIGHT-130)
    translate(WIDTH/2,HEIGHT/2)
    ang=ang+1
    rotate(ang)
    sprite(asset.builtin.Tyrian_Remastered.Evil_Head,0,0,350,350)
end

function func4()
    background(0, 255, 236)
    fill(255,0,0)
    text("Double tap screen for MENU",WIDTH/2,HEIGHT-100)
    text("Executing func2",WIDTH/2,HEIGHT-130)
    text("Add code to do something",WIDTH/2,HEIGHT/2)
end

function func5()
    background(245, 0, 255)
    fill(255)
    text("Double tap screen for MENU",WIDTH/2,HEIGHT-100)
    text("Executing func5",WIDTH/2,HEIGHT-130)
    text("Add code to do something",WIDTH/2,HEIGHT/2)
end