I NEED HELP (pls)

No, actually that didn’t help me

This is a very big app, maybe I’ll change it now

@Killer.Jo - did you reload after I made two lots of modification to the code ? I just overwrote the existing code with updated code rather than posting another new message.

No, not yet, but just now and it’s the same except for the code, of course

Maybe you could make a code that displays a button, and when you click the button, a next button comes and instead of a next button coming I can also decide what comes instead of the button. This loop should always be able to continue then you have completely fulfilled my wish 100% (I think) and that means a lot to me.

@Killer.Jo Reading thru all of your above posts, it sound like you don’t know what you want. Programming isn’t about maybe this or maybe that or could be this or could be that. As @Bri_G mentioned somewhere above, you need to sit down and decide exactly what you want to happen, step by step. If you press a button on this screen, you want this to happen. If you want multiple things to happen then you should have multiple buttons to choose from. People here are willing to help you, but it’s a waste of time constantly trying to write code when it’s something different each time. Don’t give up on programming because it’s a lot of fun and you’ll really enjoy it, but you need to know what you want to do before you try to write code. If you’re just learning, then it’s better to write very small programs that do 1 thing and play with them until you understand what they do. Then you keep expanding the size of the programs as you learn more and more new statements/functions. I’ve been programming with Codea since 2012 and I’m not tired or bored with it. It’s totally fun.

1 Like

@Killer.Jo I don’t know if this is close to what you want because I don’t know what you want.

viewer.mode=FULLSCREEN

function setup()
    rectMode(CENTER)
    sc1=true
end

function draw()
    if sc1 then
        screen1()    
    elseif sc2 then
        screen2()
    elseif sc3 then
        screen3()
    end
end

function clearSc()
    sc1,sc2,sc3=false,false,false
end

function screen1()
    background(236, 204, 67)
    fontSize(80)
    text("Screen 1",WIDTH/2,HEIGHT-200)    
    fontSize(20)
    
    fill(255)
    rect(WIDTH/2,HEIGHT/2,140,50)
    fill(0)
    text("Goto Screen2",WIDTH/2,HEIGHT/2) 
    
    fill(255)
    rect(WIDTH/2,HEIGHT/2-100,140,50)
    fill(0)
    text("Goto Screen3",WIDTH/2,HEIGHT/2-100) 
end

function screen2()
    background(160, 236, 67)
    fontSize(80)
    text("Screen 2",WIDTH/2,HEIGHT-200)
    fontSize(20) 
    fill(255)
    rect(WIDTH/2,HEIGHT/2,140,50)
    fill(0)
    text("Goto Screen1",WIDTH/2,HEIGHT/2) 
    
    fill(255)
    rect(WIDTH/2,HEIGHT/2-100,140,50)
    fill(0)
    text("Goto screen3",WIDTH/2,HEIGHT/2-100) 
end

function screen3()
    background(67, 151, 236)
    fontSize(80)
    text("Screen 3",WIDTH/2,HEIGHT-200)
    fontSize(20)
    
    fill(255)
    rect(WIDTH/2,HEIGHT/2,140,50)
    fill(0)
    text("Goto screen1",WIDTH/2,HEIGHT/2) 
    
    fill(255)
    rect(WIDTH/2,HEIGHT/2-100,140,50)
    fill(0)
    text("Back to editor",WIDTH/2,HEIGHT/2-100) 
end

function touched(t)
    if t.state==BEGAN then
        -- top button
        if t.x>WIDTH/2-70 and t.x<WIDTH/2+70 and 
                t.y>HEIGHT/2-25 and t.y<HEIGHT/2+25 then
            if sc1 then
                clearSc()
                sc2=true
            elseif sc2 then
                clearSc()
                sc1=true
            elseif sc3 then
                clearSc()
                sc1=true
            end
        end
        -- bottom button
        if t.x>WIDTH/2-70 and t.x<WIDTH/2+70 and 
                    t.y>HEIGHT/2-100-25 and t.y<HEIGHT/2-100+25 then
            if sc1 then
                clearSc()
                sc3=true
            elseif sc2 then
                clearSc()
                sc3=true
            elseif sc3 then
                clearSc()
                viewer.close()
            end
        end
    end
end

Ok. I read through everything. I’ll start with a small “program” now, then I’ll give you my little program

@Bri_G @dave1707


time = os.date("*t")
stunde = time.hour
minute = time.min

function draw()
    fill(255, 249, 0)
    font("Arial-BoldMT")
    fontSize(20)
text("Current Time: " .. stunde .. ":" .. minute,200, 800)
    
    
    end

I just made a really “cool” program with a youtube tutorial that shows the time!!!

@Killer.Jo - that’s the way to do it, bit by bit learning something new each time until you realise - it’s basically straight forward. Just needs a little time and patience.

@Killer.Jo As @Bri_G said, start small and easy. Make changes to try different things. Then when you understand what you did each time, add more or start another project with something new. Keep doing that and before you know it, you’ll be writing bigger and more complex code. Some of the things that you’ll probably use the most are “for” loops and “tables”. Another suggestion is to look thru the documentation. Don’t try to understand everything, but just kind of skim thru what it says about the commands. That way when you write code and want to do something, you’ll say I remember seeing something that will do that. In other words, you need to know how each command works so you can properly use it. That’s how I started when first using Codea. Of course, 11 years later and I still don’t know everything and I don’t expect to. It’s an ongoing process.

@Killer.Jo @dave1707 - yes, those are good suggestions if you follow them you will gradually build up a background of knowledge that helps you identify what you need and where to find the data/approach. Searching the forum will help but you must have a reasonable level of understanding to progress. It will take time.

To show how things take time and a lot of work and testing I’ll point you to a series of articles by a very experienced programmer who wanted to learn Codea and Lua. His name is Ron Jeffries and has posted many times on the forum. He has a very distinct style of programming - very professional and his posts show his thought processes in building up code. This was his first project in Codea, each step is described in detail.

Asteroids game

I must emphasise that it will take more work from you before you can fully follow his work but it does show how you break a project down into smaller parts and play with the code until it meets your needs.

I once went on a training package with my work for managing projects -
They asked the question how do you eat an elephant ?

The answer was - elephant burgers.

In other words in small portions over time.

Hope your translation software can deal with all this, if nothing else you may find your English getting better.

1 Like

function draw()
    sprite(asset.builtin.UI.Blue_Button_04, 550, 500)
    
     if CurrentTouch.state == BEGAN and CurrentTouch.x >= 500 and CurrentTouch.x <= 550 and CurrentTouch.y >= 500 and CurrentTouch.y <= 550 then
        background(255)
        
    end
end

This is an example code. If you click the button, then you can still click on the button and it would still be executed. That’s my real problem (if you don’t understand me, I can’t explain well)

@Killer.Jo What you’re program is doing is

  1. shows a black background and a blue button when started.

  2. when you touch the button, you set the background to white and show a blue button.

  3. when you lift your finger, you’re still telling it to show the blue button and the white background was the last color you said to show.

You need to tell a program exactly what you what done each step of the way.

Here’s an example showing what happenes when you touch the screen, move your finger on the screen, and then lift your finger off the screen. I’m telling it what to do for each different action I’m taking.

Instead of using CurrentTouch, you should learn more about the touched(t) function. It gives you more control over what happens when you touch the screen. Then stop using CurrentTouch.

You’re doing great. Take little steps so you learn what things do and keep expanding to learn more.

viewer.mode=FULLSCREEN

function setup()
   ellipseColor=color(255) -- set initial ellipse color
end

function draw()
    background(236, 169, 67)
    fill(ellipseColor)          -- set ellipse color
    ellipse(WIDTH/2,HEIGHT/2,200,100)   -- draw ellipse
end

function touched(t)
    if t.state==BEGAN then
        ellipseColor=color(255,0,0)-- set to red when finger touches screen
    end
    if t.state==CHANGED then
        ellipseColor=color(0,255,0)-- set to green when finger is moving
    end
    if t.state==ENDED then
        ellipseColor=color(0,0,255)-- set to blue when finger is lifted
    end
end

@Bri_G Can you help me? @dave1707 Unfortunately, you couldn’t help me so well, but a little bit. Maybe @Bri_G can help me. That would be very nice

@Killer.Jo If you could tell us exactly what you want a program to do, step by step, we can give you an example that does exactly that. Giving us a one line program and then asking us why it doesn’t do everything you want it to do doesn’t help us any. Your above code did exactly what you told it to do. What else you were expecting it to do we don’t know. We want to help, but if we don’t know what you want, we can only guess.

I have a question that might help us, but you don’t need to answer if you don’t want.

How old are you and how much programming experience do you have.

I’m 75 with 48 years experience and I’m still learning. We all start with no experience but build on that as we learn by trial and error.

I’m 12 and don’t have that much experience, I’ve only had codea for a few months. I wouldn’t have appreciated her that old now, but that shouldn’t sound offensive at all. So, the problem I have is when I create a button and I click it (the button), then everything works up to here, but if I click on the “touch” again now, the button still works. And I don’t want the button to work when I click on it (the button) (otherwise it wouldn’t be a button) I hope that helps you

@Killer.Jo That’s probably a perfect age to start learning to program. You probably understand logic, you can understand how different commands/functions work and you probably won’t give up when things get a little frustrating.

Back to your program.

You press the button and it changes the background color. The program still has code to show the button and accept a touch on it.

So, what do you want to happen after you press the button the first time.

@Killer.jo - don’t panic, @dave1707 has provided you with a good example. You need to think about what you need. Codea usually likes to use a framework with the three functions in it:

Function setup() is there to set up any variables, data and conditions before the project can run, so I woul put a variable in there to us for making your button active or inactive.

Function draw() should contain all the code you need to display what you need on the screen, background() should be placed there at the top of the draw() code. It should also hold your code to display your button but in and if loop to display only when your button variable is active.

Function touched() should be used to capture touches on the screen. If it is a simple touch like a switch you should use the condition ENDED in the if statement and then check the button active variable and adjust if needed.

I’ll post the code later when I have recharged my pad.

I would avoid CurrentTouch() for the moment and stick to using the touched function, much better when learning Codea.

Is this closer to what you’re after. Now that the button is gone, what do you want to do. Remember that you have to tell the program everything you want it to do, step by step. To tell it, use “if” statements. Either do this or do that.

function setup()
    bgColor=color(0)    -- background color to start  with
end

function draw()
    background(bgColor)-- show the background color
    if not buttonPressed then   -- if the button wasnt pressed
        sprite(asset.builtin.UI.Blue_Button_04, 550, 500) -- show button  

        if CurrentTouch.state == BEGAN then -- check if the button is pressed        
            if CurrentTouch.x >= 550-75 and CurrentTouch.x <= 550+75 and 
            CurrentTouch.y >= 500-19 and CurrentTouch.y <= 500+19 then  
                buttonPressed=true      -- button was pressed, so set the flag
                bgColor=color(255)  -- set the new background color
            end      
        end
    end
end