Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Need help

edited July 2013 in General Posts: 4

How do I make a quiz game any tips? How can I make it have right and wrong answers?
Also any good video tutorials out there for this app? I am more of a audible learner.


  • dave1707dave1707 Mod
    Posts: 8,450

    Set up 5 tables. One table for the question, one table for the correct answer. The three other tables will have the wrong answers. Each offset into the tables will be for that question. For example, the first entry of all the tables. Table 1, "What is the distance to the moon. Table 2, 238,900 miles. Table 3, 150,000 miles. Table 4, 400,560 miles. Table 5, 275,134 miles. Pick random numbers so that the 4 answers will be in different positions. Since you know the correct answer was in table 2 and you know what position you put it, you'll know if the selected the correct answer.

  • BriarfoxBriarfox Mod
    edited July 2013 Posts: 1,542

    @Aulis98 Please don't make multiple posts with the same question. People responded to your previous post with some good tutorial links. If you have specific questions please feel free to follow up in that thread but do not create a new one unless it's in regards to a different question.

    If you are not entirely sure what @dave1707 was saying I'd start with @ignatz ebook in the previous thread to get a better understanding of Lua and codea.

  • Posts: 4

    @briarfox Sorry, thank you for the help and I won't again

  • dave1707dave1707 Mod
    edited July 2013 Posts: 8,450

    @Aulis98 There are different ways of doing what you want, but here is something quick to get you going. You can modify this to add all your bells and whistles.

    EDIT: Tap what you think is the correct answer.

    displayMode(FULLSCREEN) function setup()     question={}     correct={}     wrong1={}     wrong2={}     wrong3={}     fillTables()     askQuestion=true       answer={a1,a2,a3,a4}       q=1     str=""     -- x,y values for questions and answers     t1=vec2(300,400)    -- question     t2=vec2(300,350)    -- answers     t3=vec2(300,300)     t4=vec2(300,250)     t5=vec2(300,200)     t6=vec2(300,500)    -- correct / wrong response end function draw()     background(40, 40, 50)     sprite("SpaceCute:Background",WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)     fill(255)     if askQuestion then         if q<=#question then             c=math.random(1,4)             func=answer[c]         end         if str=="correct" then             q=q+1             if q>#question then                 func=done             end         end         askQuestion=false     end     text(str,t6.x,t6.y)     func() end function a1()     text(question[q],t1.x,t1.y)     text(correct[q],t2.x,t2.y)     text(wrong1[q],t3.x,t3.y)     text(wrong2[q],t4.x,t4.y)      text(wrong3[q],t5.x,t5.y) end function a2()     text(question[q],t1.x,t1.y)     text(wrong1[q],t2.x,t2.y)     text(correct[q],t3.x,t3.y)     text(wrong2[q],t4.x,t4.y)      text(wrong3[q],t5.x,t5.y) end function a3()     text(question[q],t1.x,t1.y)     text(wrong1[q],t2.x,t2.y)     text(wrong2[q],t3.x,t3.y)     text(correct[q],t4.x,t4.y)      text(wrong3[q],t5.x,t5.y) end function a4()     text(question[q],t1.x,t1.y)     text(wrong1[q],t2.x,t2.y)     text(wrong2[q],t3.x,t3.y)     text(wrong3[q],t4.x,t4.y)      text(correct[q],t5.x,t5.y) end function done()     str="no more questions" end      function touched(t)     if t.state==ENDED then         str=""         if t.y>t2.y-25 and t.y<t2.y+25 then             if c==1 then str="correct" else str="wrong" end         end         if t.y>t3.y-25 and t.y<t3.y+25 then             if c==2 then str="correct" else str="wrong" end         end         if t.y>t4.y-25 and t.y<t4.y+25 then             if c==3 then str="correct" else str="wrong" end         end         if t.y>t5.y-25 and t.y<t5.y+25 then             if c==4 then str="correct" else str="wrong "end         end         if str~="" then             askQuestion=true         end     end end function fillTables()     question[1]="What is the distance to the moon"     correct[1]="238,900 miles"     wrong1[1]="225,000 miles"     wrong2[1]="275,450 miles"     wrong3[1]="310,340 miles"          question[2]="What is the largest planet"     correct[2]="Jupiter"     wrong1[2]="Mars"     wrong2[2]="Saturn"     wrong3[2]="Venus"          question[3]="What is the largest ocean"     correct[3]="Pacific"     wrong1[3]="Atlantic"     wrong2[3]="Arctic"     wrong3[3]="Indian" end


  • BriarfoxBriarfox Mod
    Posts: 1,542

    @Aulis98 Not a problem, We have a great community here thats very willing to lend a hand. @dave1707 's code should give you a great starting point.

  • edited July 2013 Posts: 391

    @Aulis98, @dave1707's code is definitely a great start like @Briarfox said. However, I would make one quick change to the touched function. Currently, it says wrong if you touch outside of the choices as well as if you touch a wrong choice. Swap out the touched function above with this one and that will be resolved:

    function touched(t)
        if t.state==ENDED then
            if t.y>325 and t.y<375 then
                if c==1 then str="correct" else str="wrong" end
            if t.y>275 and t.y<325 then
                if c==2 then str="correct" else str="wrong" end
            if t.y>225 and t.y<275 then
                if c==3 then str="correct" else str="wrong" end
            if t.y>175 and t.y<225 then
                if c==4 then str="correct" else str="wrong" end
            if str~="" then
  • IgnatzIgnatz Mod
    Posts: 5,396

    @Aulis98 - sorry, no audio/video tutorials.

    Codea is too small a community, and everything like that has to be user-created. However, the good part is that because we are small, we help each other out a lot, and this forum is the second best thing about Codea.

  • Posts: 4

    So I have a better understanding on how everything works and I'm not as in the dark as I was, but I'm trying to move the location of the text I'm not sure how to do that with out messing everything up, also can I have a image for the back ground?

  • Posts: 2,043

    @Aulis98, Sure you can have an image as a background! Just do

    function setup()
        backgroundImage = readImage("WhateverItIs")
    function draw()
        sprite(backgroundImage, WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
        -- All of the other stuff --

    This will draw the image in the middle of screen with the correct size to cover the entire screen. Everything else comes after it so that it will be the back

  • dave1707dave1707 Mod
    Posts: 8,450

    @Aulis98 I modified the original program above to make it easier to move the text around. I also included the changes suggested by @JakAttak and @Slashin8r. Just change the values of t1 thru t6. Also if you change the text size, you'll have to change the -25 and +25 in the touch routine.

Sign In or Register to comment.