Howdy, Stranger!

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

Help Needed!

edited November 2016 in Questions Posts: 87

When I tap on the screen it should switch screens
Why doesn't it do that?
Can you fix it so it does?

My Code


--# Colours Colours = class() function Colours:init(x) -- you can accept and set parameters here blue=color(0, 246, 255, 255) black=color(0, 0, 0, 0) white=color(255, 255, 255, 255) darkblue=color(56, 0, 255, 255) orange=color(255, 148, 0, 255) end function Colours:draw() end function Colours:touched(touch) end --# Main --[[ For Art Tech Project Due:November 30,2016 --]] --displayMode(FULLSCREEN_NO_BUTTONS) supportedOrientations(PORTRAIT) function setup() cam = vec2(0,0) gameState=0 Colours:init() howfardown=10 parameter.watch("CurrentTouch.y") parameter.watch("CurrentTouch.x")--Parameters parameter.integer("howfardown", 0, 1000, 5) end function draw() if gameState==0 then translate(cam.x,cam.y) background(white) strokeWidth(10) stroke(0, 0, 0, 255) --Lines line(0,490,WIDTH,490)--Line umderneath graph line(WIDTH/2,490,WIDTH/2,10)--Line Between Most and least Productive day strokeWidth(20) line(0,10,WIDTH,10) fill(darkblue) noStroke() rect(0,HEIGHT-100,WIDTH,200) font("AmericanTypewriter-CondensedBold") fill(0, 0, 0, 255) fontSize(40) text("Productive",WIDTH/2,HEIGHT-56) fill(orange) rect(75,884.5,30,30)--For legend fill(blue) rect(470,884.5,30,30)--For legend fill(orange) rect(10,500,100,300)--For graph (Non productive) rect(260,500,100,250)--Add 250 to x value space between non productive graphs rect(520,500,100,300) fill(blue) rect(110,500,100,200)--For Graph (Productive) rect(360,500,100,350) rect(620,500,100,240) fill(0, 0, 0, 255) textSize(8) text("Most Productive Day",200,450) text("Least Productive Day",570,450) fill(orange) rect(70, 25, 100, 30)--For Most Productive day fill(blue) rect(170, 25, 100, 300)--For Most Productive day fill(orange) rect(WIDTH/2+76,25,100,310)--For Least Productive day fill(blue) rect(WIDTH/2+76+100,25,100,10)--For least Productive Day textSize(2) fill(0, 0, 0, 255) text("Productive",200,900) text("Non-Productive",652-20,900) end if CurrentTouch.x > 0 then gameState=2 end if gameState==2 then text("Question",200,200) end end

Comments

  • dave1707dave1707 Mod
    Posts: 7,602

    You need a background(some color) command after function draw(). Then you also need a fill(some color) command before text("Question",200,200). That should get you going again.

  • edited November 2016 Posts: 87

    @dave1707
    I'm so sorry to bother you again but can you please answer one more question :smile:

    How come when I tap the (in game state 2) the rectangle it doesn't switch my gameState back to 0?

    The problem is on line 108 and 116

    My Code


    --# Colours Colours = class() function Colours:init(x) -- you can accept and set parameters here blue=color(0, 246, 255, 255) black=color(0, 0, 0, 0) white=color(255, 255, 255, 255) darkblue=color(56, 0, 255, 255) orange=color(255, 148, 0, 255) end function Colours:draw() end function Colours:touched(touch) end --# Main --[[ For Art Tech Project Due:November 30,2016 --]] --displayMode(FULLSCREEN_NO_BUTTONS) supportedOrientations(PORTRAIT) function setup() cam = vec2(0,0) gameState=0 Colours:init() howfardown=10 HowManyQuestions=0 HowManyYes=0 HowManyNo=0 YesPercentange=0 NoPercentage=0 parameter.watch("CurrentTouch.y") parameter.watch("CurrentTouch.x")--Parameters end function draw() YesPercentange=HowManyYes/HowManyQuestions*100 NoPercentage=HowManyNo/HowManyQuestions*100 --print(YesPercentange) if gameState==0 then translate(cam.x,cam.y) background(white) strokeWidth(10) stroke(0, 0, 0, 255) --Lines line(0,490,WIDTH,490)--Line umderneath graph line(WIDTH/2,490,WIDTH/2,10)--Line Between Most and least Productive day strokeWidth(20) line(0,10,WIDTH,10) fill(darkblue) noStroke() rect(0,HEIGHT-100,WIDTH,200) font("AmericanTypewriter-CondensedBold") fill(0, 0, 0, 255) fontSize(40) text("Productive",WIDTH/2,HEIGHT-56) fill(orange) rect(75,884.5,30,30)--For legend fill(blue) rect(470,884.5,30,30)--For legend fill(orange) rect(10,500,100,300)--For graph (Non productive) rect(260,500,100,250)--Add 250 to x value space between non productive graphs rect(520,500,100,300) fill(blue) rect(110,500,100,200)--For Graph (Productive) rect(360,500,100,350) rect(620,500,100,NoPercentage*100)--Today fill(0, 0, 0, 255) textSize(8) text("Most Productive Day",200,450) text("Least Productive Day",570,450) fill(orange) rect(70, 25, 100, 30)--For Most Productive day fill(blue) rect(170, 25, 100, 300)--For Most Productive day fill(orange) rect(WIDTH/2+76,25,100,310)--For Least Productive day fill(blue) rect(WIDTH/2+76+100,25,100,10)--For least Productive Day textSize(2) fill(0, 0, 0, 255) text("Productive",200,900) text("Non-Productive",652-20,900) end if CurrentTouch.x > 0 then gameState=2 end if gameState==2 then background(white) fill(blue) rect(100,512,200,200) rect(525,512,200,200) text("Are You Productive?",WIDTH/2,HEIGHT-100) end end function touched(t) if t.state==BEGAN and CurrentTouch.y < 733.5 and CurrentTouch.y > 487 and CurrentTouch.x > 70 and CurrentTouch.x < 350 then HowManyQuestions=HowManyQuestions+1 HowManyYes=HowManyYes+1 gameState=0--Were The problem is elseif t.state==BEGAN and CurrentTouch.y < 733.5 and CurrentTouch.y > 487 and CurrentTouch.x > 510 and CurrentTouch.x < 760 then HowManyQuestions=HowManyQuestions+1 HowManyNo=HowManyNo+1 gameState=0--Were the problem is end end
  • dave1707dave1707 Mod
    Posts: 7,602

    Get rid of CurrentTouch and just use the touched function. Once you touch the screen, CurrentTouch always retains its value, so the statement if CurrentTouch.x > 0 is always true and you always set gameState=2.

  • edited November 2016 Posts: 87

    Edit:
    Solved! Thanks :smile:

  • How come when str equals something in the words array the Yes and No percentage mess up?

      function setup()
        HowManyQuestions=0
        HowManyYes=0
        HowManyNo=0
        YesPercentage=0
        NoPercentage=0
        str="math"
        parameter.watch("YesPercentage")
        parameter.watch("NoPercentage")
    
        Words={
        "Math",
        "math",
        "science",
        "addition",
        "subtraction",
        "physics",
        "work",
        "study",
        "exponents",
        "area",
        "to the power",
        "squared",
        "formula",
        "multiply",
        "how",
        "code",
        "divide",
        "sum",
        "quotient",
        "productive",
        "multiplying",
        "dividing",
        "productive app"
        }
    
        for i=1,22 do
    
             if str==Words[i]
            then  
        HowManyQuestions=HowManyQuestions+1
        HowManyYes=HowManyYes+1
    
            elseif
                Words[23]
                then         
            HowManyQuestions=HowManyQuestions+1
            HowManyNo=HowManyNo+1
                end
        end
        end
    
    function draw()    
    YesPercentage=HowManyYes/HowManyQuestions*100
    NoPercentage=HowManyNo/HowManyQuestions*100
    end
    
  • dave1707dave1707 Mod
    Posts: 7,602

    @magicskillz I think it's time you learn how to use the print and/or watch statements to find your own problems. You're already using watch, so you're off to a good start. Just keep checking different values until you narrow down the problem. That's pretty much the same thing I have to do to find your errors.

  • Solved Thx for the tip!

Sign In or Register to comment.