Create a Math Game

Try this.

displayMode(FULLSCREEN)

function setup()
    tchStart=0
end

function draw()
    background(40, 40, 50)
    fill(255)
    if tchStart~=0 then
        text("Screen touched for "..((ElapsedTime-tchStart)//1).." seconds.",WIDTH/2,HEIGHT/2)
    end 
    text("touch the screen",WIDTH/2,HEIGHT-100)   
end

function touched(t)
    if t.state==BEGAN then
        tchStart=ElapsedTime
    end 
    if t.state==ENDED then
        tchStart=0
    end
end

Thanks @dave1707 Now I’ll try and combine that into the store code.

@CodingIsLife, yes, that’s what I meant

and when the touch ends, you can check how long it was held

Hey forum, I’ve got a question about the speech command. In a program I’m making I would like to take advantage of Codea’s speech command and use it for a tutorial scene. In the tutorial scenes, the user if presented with text in a box telling them how to play this game. I know I could just do speech.say("blah") but I’d like to have the tutorial in other languages; just to make the program diverse. I was thinking that in the settings menu, the user can select a language and there’s an if statement in the touch function changing some variable that’d hold onto the preferred language. Then, I’d use that variable in each tutorial scene checking what the language is and then getting the program to speak in that language. The scenes have short sentences in which I could get people to translate for me and I could use speech.language to adjust the accent of the program.

What I want to know if what is the best way to do this? I had an idea to use a table but I’m not a genius with that. It’d be annoying to have long if/elseif statements checking what the preferred language is. Thanks :slight_smile:

@CodingIsLife - tables, tables, tables.

You can’t write too many Codea programs without using them, so I would just learn them, it’s well worth it.

there are many ways to do it, but for example

Words={
  hello={"hello", "bonjour","guten dag", etc},
  goodbye=["goodbye","au revoir", etc},
  ["Menu 1"]={"Settings", etc}, --do it this way if name includes spaces
  etc
}

Then you choose a language L, which is a number 1,2,3… (English=1, French=2, German=3 etc)

and saying something is just speech.say(Words.hello[L])

https://codea.io/talk/discussion/7105/speech-library

Thanks @TokOut I’ve already read through that but I’m not sure if that’s what I’m looking for. If it comes to it I’ll just write long if/elseif statements

Thanks @Ignatz I’ll look into studying tables some more. For now I’ll probably just use English since it’s so universal. Maybe in a later version I’ll add a table of languages.

Hey, Codea Talk users. I’ve taken a break from coding since I didn’t have it as a class, but I decided recently to revisit an old project. It’s the Math Game this post was about. I’m trying to add more GUI to it like a store and difficulty and what not. [solved sort of]

[solved highscore issue]