Howdy, Stranger!

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

Survey help.

Im looking for a basic understand of a userinput survey. So it would display what a, b and c are and you would type the letter based on the answer assigned to the letter. And it would switch scenes for every question.

Comments

  • I had a look at that but i didnt seem to like that logic

  • dave1707dave1707 Mod
    Posts: 7,469

    That example showed a question and let you select an answer. It then continued showing questions/answers until there were no more questions. There's code in there that you wouldn't need, but you would remove that and add your code. I guess I don't understand exactly what you're after then.

  • I want basically, you pick one out of 4 options ( which are buttons) and the question is displayed above.

  • dave1707dave1707 Mod
    Posts: 7,469

    Can you give one example of the 4 options and the questions that would pop up. Maybe if I can see what you want I can whip up another example.

  • What is your age? , 1-10,10-15,15-20,20-80

  • dave1707dave1707 Mod
    Posts: 7,469

    That was basically the program I showed you above. Here's a modified version of it. You'll have to add code to the touched function depending on what you want to do with the answer you select. Does this work for you.

    function setup()
        questions()
        answers()
        quest=1
    end
    
    function draw()
        background(40, 40, 50)
        fill(255)
        if quest<=#qTab then
            fill(255)
            rect(50,650,400,80)
            rect(50,450,400,80)
            rect(50,350,400,80)
            rect(50,250,400,80)
            rect(50,150,400,80)
            fill(255,0,0)
            text(qTab[quest],200,700)
            text(aTab[quest][1],200,500)
            text(aTab[quest][2],200,400)
            text(aTab[quest][3],200,300)
            text(aTab[quest][4],200,200)
    
        else
            text("No more questions",WIDTH/2,HEIGHT/2)
        end
    end
    
    function questions()
        qTab={}
        table.insert(qTab,"What is your age.")
        table.insert(qTab,"How tall are you.")
        table.insert(qTab,"This is question 3")
        table.insert(qTab,"This is question 4")
        table.insert(qTab,"This is question 5")
    end
    
    function answers()
        aTab={}
        table.insert(aTab,{"1-10 years","11-15 years","16-20 years","21-80 years"})  
        table.insert(aTab,{"3-4 feet","4-5 feet","5-6 feet","6-7 feet"})  
        table.insert(aTab,{"ans3-1","ans3-2","ans3-3","ans3-4"})  
        table.insert(aTab,{"ans4-1","ans4-2","ans4-3","ans4-4"})  
        table.insert(aTab,{"ans5-1","ans5-2","ans5-3","ans5-4"})  
    end
    
    function touched(t)
        if t.state==ENDED and quest<=#qTab then
            if t.x>0 and t.x<WIDTH and t.y>450 and t.y<550 then
                quest=quest+1
            end
            if t.x>0 and t.x<WIDTH and t.y>350 and t.y<450 then
                quest=quest+1
            end
            if t.x>0 and t.x<WIDTH and t.y>250 and t.y<350 then
                quest=quest+1
            end
            if t.x>0 and t.x<WIDTH and t.y>150 and t.y<250 then
                quest=quest+1
            end
        end    
    end
    
  • edited November 2016 Posts: 8

    Here this is what i came up with, Is there i way i can add a restart button at the end? And a way to simplifiy this messyness? The purpose of the program is an adult test to see if your ready to move out or not based on the answers.

    supportedOrientations(PORTRAIT_ANY)
    displayMode(FULLSCREEN)
    
    function setup()
        questions()
        answers()
        values()
        score=0
        quest=1
    
         r = math.random(1,255)
         g = math.random(1,255)
         b = math.random(1,255)
    
            -- setup sparkles for background
        show_poles = nil
        length = 200    -- tail length
        dA = 10         -- angle variation
        sA = 45         -- starting angle
        respawn = 0.01   -- respawn frequence in seconds
        sparkles = {}
        spawncounter=0
    end
    
    function draw()
        background(r, g, b, 255)
        fill(255, 255, 255, 255)
        if quest<=#qTab then
    
            fontSize(25)
            text(qTab[quest],WIDTH/2,700)
    
            fontSize(20)
            font("AmericanTypewriter-Bold")
            text(aTab[quest][1],WIDTH/2,500)
            text(aTab[quest][2],WIDTH/2,400)
            text(aTab[quest][3],WIDTH/2,300)
            text(aTab[quest][4],WIDTH/2,200)
        else
            if (score >= 24) then
                fontSize(25)
                text("You have proved yourself, your ready to move out.",WIDTH/2,HEIGHT/2)       
                length = 200    -- tail length
                dA = 100         -- angle variation
                sA = 453         -- starting angle
            elseif (score <= 24) then
                fontSize(25)
                text("Your almost there but your still not ready to move out.",WIDTH/2,HEIGHT/2)
                length = 200    -- tail length
                dA = 100         -- angle variation
                sA = 453         -- starting angle
            end
        end
        fontSize(30)
        font("ArialRoundedMTBold")
        text("SCORE  "..score,WIDTH/2,HEIGHT-50)
    end
    
    function questions()
        qTab={}
        table.insert(qTab,"What is your gender?")
        table.insert(qTab,"What is your age?")
        table.insert(qTab,"Are you currently employed or have been employed?")
        table.insert(qTab,"If yes, have you ever been fired?")
        table.insert(qTab,"How much money do you currently have saved?")
        table.insert(qTab,"Have you received a high school diploma?")
        table.insert(qTab,"Do you do chores in your household?")
        table.insert(qTab,"Can you trust people?")
        table.insert(qTab,"Can people trust you?")
        table.insert(qTab,"Do you feel guilty when your at fault? (I.e) a car crash")
        table.insert(qTab,"Do you feel empanthy for others?")
        table.insert(qTab,"Can you love someone else?")
        table.insert(qTab,"Do you love yourself?")
        table.insert(qTab,"Do you feel you can make it in the world?")
        table.insert(qTab,"Are men and woman equal?")
        table.insert(qTab,"Have you ever been addicted to drugs, alcohol, etc?")
        table.insert(qTab,"Do you believe you are currently being oppressed?")
        table.insert(qTab,"Do you have any disabilities that hinder your daily life?")
        table.insert(qTab,"Do you believe you have a purpose in this world?")
        table.insert(qTab,"Do your parents want you to move out?")
        table.insert(qTab,"Do you believe you are ready to move out?")
    end
    
    function answers()
        aTab={}
        table.insert(aTab,{"Male","Female","Other","Apache Attack Helicopter"})  
        table.insert(aTab,{"15-17","18-21","22-28","29+"})  
        table.insert(aTab,{"Yes","No (Worked under minimum wage)","No (Was never employed)",""})  
        table.insert(aTab,{"N/A","Yes","No",""})  
        table.insert(aTab,{"$100-$500","$500-$2,000","$2,000-$6,000","$10,000+"})  
        table.insert(aTab,{"Yes","No (Dropped out)","No (Never went to high school)","No (Failed high school)"})  
        table.insert(aTab,{"Yes","No","",""})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
        table.insert(aTab,{"No, Men are superior to Women","No, Women are superior to Me n","No, I hate everyone","Yes, Men and Women are equal"})  
        table.insert(aTab,{"No, (Tried them but never got addicted)","No, (Never tried it)","Yes, but I overcame the addiction","Yes, and I'm currently addicted to something"})  
        table.insert(aTab,{"Yes","No","Don't know",""}) 
        table.insert(aTab,{"Yes, I suffer from atleast one Mental disability","Yes, I suffer from atleast one Physical disability","Yes, I suffer from Mental and Physical disabilities","No, I do not suffer from any disabilites"})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
        table.insert(aTab,{"Yes","No","Don't know",""})  
    end
    
    function values()
        sTab={}
        table.insert(sTab,{1,1,0,9000})
        table.insert(sTab,{0,1,2,0})
        table.insert(sTab,{3,2,0,0})
        table.insert(sTab,{0,0,1,0})
        table.insert(sTab,{1,2,3,4})
        table.insert(sTab,{2,1,0,0})
        table.insert(sTab,{1,0,0,0})
        table.insert(sTab,{1,0,0,0})
        table.insert(sTab,{1,0,0,0})
        table.insert(sTab,{1,0,0,0})
        table.insert(sTab,{1,0,0,0})
        table.insert(sTab,{1,0,0,0})
        table.insert(sTab,{1,0,0,0})
        table.insert(sTab,{1,0,0,0})
        table.insert(sTab,{0,0,0,1})
        table.insert(sTab,{1,2,1,0})
        table.insert(sTab,{0,1,0,0})
        table.insert(sTab,{1,1,0,2})
        table.insert(sTab,{0,1,0,0})
        table.insert(sTab,{1,0,0,0})
        table.insert(sTab,{1,0,0,0})
    end
    
    function touched(t)
        if t.state==ENDED and quest<=#qTab then
            if t.x>0 and t.x<WIDTH and t.y>450 and t.y<550 then
                score=score+sTab[quest][1]
                quest=quest+1
                  r = math.random(1,255)
                  g = math.random(1,255)
                  b = math.random(1,255)
                  sound(SOUND_JUMP, 49362)
            end
            if t.x>0 and t.x<WIDTH and t.y>350 and t.y<450 then
                score=score+sTab[quest][2]
                quest=quest+1
                  r = math.random(1,255)
                  g = math.random(1,255)
                  b = math.random(1,255)
                  sound(SOUND_PICKUP, 22679)
            end
            if t.x>0 and t.x<WIDTH and t.y>250 and t.y<350 then
                score=score+sTab[quest][3]
                quest=quest+1
                  r = math.random(1,255)
                  g = math.random(1,255)
                  b = math.random(1,255)
                 sound(SOUND_BLIT, 14885)
            end
            if t.x>0 and t.x<WIDTH and t.y>150 and t.y<250 then
                score=score+sTab[quest][4]
                quest=quest+1
                  r = math.random(1,255)
                  g = math.random(1,255)
                  b = math.random(1,255)
                 sound(SOUND_PICKUP, 38590)
    
            end
        end    
    end
    
  • dave1707dave1707 Mod
    Posts: 7,469

    In the code where quest > #qTab, add another text that says to tap the screen to restart. In the touched function, add code that calls restart if the screen is tapped.

  • edited November 2016 Posts: 2,020

    @dave1707 @durnonimous all those table.insert commands, yuck! You don't them, you can declare table by placing the values inside the curly braces:

    eg:

    function values()
        sTab={
        {1,1,0,9000},
        {0,1,2,0},
        {3,2,0,0}
        -- ... lots more values here
        }
    

    etc

    is much more readable.

  • dave1707dave1707 Mod
    Posts: 7,469

    @yojimbo2000 You're correct about the table entries. I'm not sure why I did the table.insert to start with, but apparently I just copied the lines of code.

  • Posts: 2,020

    Everyone's code needs another pair of eyes sometimes :)

  • dave1707dave1707 Mod
    Posts: 7,469

    @durnonimous Here's the above code with the table.inserts removed. I also added the restart at the end of the questions and reduced the size of the touched function.

    supportedOrientations(PORTRAIT_ANY)
    displayMode(FULLSCREEN)
    
    function setup()
        pos={vec2(475,525),vec2(375,425),vec2(275,325),vec2(175,225)}
        s1={SOUND_JUMP,SOUND_PICKUP,SOUND_BLIT,SOUND_PICKUP}
        s2={49362,22679,14885,38590}
        questions()
        answers()
        values()
        score=0
        quest=1
        col=color(math.random(1,255),math.random(1,255),math.random(1,255))
    end
    
    function draw()
        background(col)
        fill(255, 255, 255, 255)
        if quest<=#qTab then
            fontSize(25)
            text(qTab[quest],WIDTH/2,700)
            fontSize(20)
            font("AmericanTypewriter-Bold")
            text(aTab[quest][1],WIDTH/2,500)
            text(aTab[quest][2],WIDTH/2,400)
            text(aTab[quest][3],WIDTH/2,300)
            text(aTab[quest][4],WIDTH/2,200)
        else
            fontSize(25)
            if (score >= 24) then
                text("You have proved yourself, your ready to move out.",WIDTH/2,HEIGHT/2)       
            else
                text("Your almost there but your still not ready to move out.",WIDTH/2,HEIGHT/2)
            end
            fontSize(45)
            text("Double tap the screen to restart",WIDTH/2,250)
        end
        fontSize(30)
        font("ArialRoundedMTBold")
        text("SCORE  "..score,WIDTH/2,HEIGHT-50)
    end
    
    function questions()
        qTab={
            "What is your gender?",
            "What is your age?",
            "Are you currently employed or have been employed?",
            "If yes, have you ever been fired?",
            "How much money do you currently have saved?",
            "Have you received a high school diploma?",
            "Do you do chores in your household?",
            "Can you trust people?",
            "Can people trust you?",
            "Do you feel guilty when your at fault? (I.e) a car crash",
            "Do you feel empanthy for others?",
            "Can you love someone else?",
            "Do you love yourself?",
            "Do you feel you can make it in the world?",
            "Are men and woman equal?",
            "Have you ever been addicted to drugs, alcohol, etc?",
            "Do you believe you are currently being oppressed?",
            "Do you have any disabilities that hinder your daily life?",
            "Do you believe you have a purpose in this world?",
            "Do your parents want you to move out?",
            "Do you believe you are ready to move out?",
            }
    end
    
    function answers()
        aTab={
            {"Male","Female","Other","Apache Attack Helicopter"},
            {"15-17","18-21","22-28","29+"}, 
            {"Yes","No (Worked under minimum wage)","No (Was never employed)",""},  
            {"N/A","Yes","No",""},  
            {"$100-$500","$500-$2,000","$2,000-$6,000","$10,000+"},  
            {"Yes","No (Dropped out)","No (Never went to high school)","No (Failed high school)"},
            {"Yes","No","",""},  
            {"Yes","No","Don't know",""},  
            {"Yes","No","Don't know",""}, 
            {"Yes","No","Don't know",""}, 
            {"Yes","No","Don't know",""},  
            {"Yes","No","Don't know",""},  
            {"Yes","No","Don't know",""},  
            {"Yes","No","Don't know",""}, 
            {"No, Men are superior to Women","No, Women are superior to Me n","No, I hate everyone","Yes, Men and Women are equal"},  
            {"No, (Tried them but never got addicted)","No, (Never tried it)","Yes, but I overcame the addiction","Yes, and I'm currently addicted to something"},  
            {"Yes","No","Don't know",""}, 
            {"Yes, I suffer from atleast one Mental disability","Yes, I suffer from atleast one Physical disability","Yes, I suffer from Mental and Physical disabilities","No, I do not suffer from any disabilites"},  
            {"Yes","No","Don't know",""},  
            {"Yes","No","Don't know",""},  
            {"Yes","No","Don't know",""},
            }      
    end
    
    function values()
        sTab={
            {1,1,0,9000},
            {0,1,2,0},
            {3,2,0,0},
            {0,0,1,0},
            {1,2,3,4},
            {2,1,0,0},
            {1,0,0,0},
            {1,0,0,0},
            {1,0,0,0},
            {1,0,0,0},
            {1,0,0,0},
            {1,0,0,0},
            {1,0,0,0},
            {1,0,0,0},
            {0,0,0,1},
            {1,2,1,0},
            {0,1,0,0},
            {1,1,0,2},
            {0,1,0,0},
            {1,0,0,0},
            {1,0,0,0},
            }
    end
    
    function touched(t)
        if t.state==ENDED and t.tapCount==2 and quest>#qTab then
            restart()
        elseif t.state==ENDED and quest<=#qTab then
            for z=1,4 do
                if t.x>0 and t.x<WIDTH and t.y>pos[z].x and t.y<pos[z].y then
                    score=score+sTab[quest][z]
                    quest=quest+1
                    sound(s1[z],s2[z])
                    col=color(math.random(1,255),math.random(1,255),math.random(1,255))
                end
            end
        end    
    end
    
  • dave1707dave1707 Mod
    Posts: 7,469

    @durnonimous Here's another version where everything is in one table. I just did the first 4 questions. If you like this version, you can fill in the rest of the questions.

    supportedOrientations(PORTRAIT_ANY)
    displayMode(FULLSCREEN)
    
    function setup()
        pos={vec2(475,525),vec2(375,425),vec2(275,325),vec2(175,225)}
        s1={SOUND_JUMP,SOUND_PICKUP,SOUND_BLIT,SOUND_PICKUP}
        s2={49362,22679,14885,38590}
        questions()
        score=0
        quest=1
        col=color(math.random(1,255),math.random(1,255),math.random(1,255))
    end
    
    function draw()
        background(col)
        fill(255, 255, 255, 255)
        if quest<=#qTab then
            fontSize(25)
            text(qTab[quest][1],WIDTH/2,700)
            fontSize(20)
            font("AmericanTypewriter-Bold")
            text(qTab[quest][2][1],WIDTH/2,500)
            text(qTab[quest][2][2],WIDTH/2,400)
            text(qTab[quest][2][3],WIDTH/2,300)
            text(qTab[quest][2][4],WIDTH/2,200)
        else
            fontSize(25)
            if (score >= 24) then
                text("You have proved yourself, your ready to move out.",WIDTH/2,HEIGHT/2)       
            else
                text("Your almost there but your still not ready to move out.",WIDTH/2,HEIGHT/2)
            end
            fontSize(45)
            text("Double tap the screen to restart",WIDTH/2,250)
        end
        fontSize(30)
        font("ArialRoundedMTBold")
        text("SCORE  "..score,WIDTH/2,HEIGHT-50)
    end
    
    function questions()
        qTab=
        {   {"What is your gender?",
                {"Male","Female","Other","Apache Attack Helicopter"},        
                    {1,1,0,9000}},
            {"What is your age?",
                {"15-17","18-21","22-28","29+"},
                    {0,1,2,0}},
            {"Are you currently employed or have been employed?",
                {"Yes","No (Worked under minimum wage)","No (Was never employed)",""},
                    {3,2,0,0}},
            {"If yes, have you ever been fired?",
                {"N/A","Yes","No",""},
                    {0,0,1,0}},
        }
    end
    
    function touched(t)
        if t.state==ENDED and t.tapCount==2 and quest>#qTab then
            restart()
        elseif t.state==ENDED and quest<=#qTab then
            for z=1,4 do
                if t.x>0 and t.x<WIDTH and t.y>pos[z].x and t.y<pos[z].y then
                    score=score+qTab[quest][3][z]
                    quest=quest+1
                    sound(s1[z],s2[z])
                    col=color(math.random(1,255),math.random(1,255),math.random(1,255))
                end
            end
        end    
    end
    
  • IgnatzIgnatz Mod
    Posts: 5,396

    now that is the way to store the survey data, it is much easier to make changes

  • Thank you so much for the help guys.

Sign In or Register to comment.