Howdy, Stranger!

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

I need help with my code!

edited September 2013 in Questions Posts: 116

I don't understand why is my Codea stopping after the block goes behind the boy.
I think I made everything right.
Can somebody help me?
Thank you!
Here is my code

-- Jump n' Run -- Use this function to perform your initial setup function setup() boy=Boy() boy.position = vec2(0, 0) move=0 howMany=0 milsec=1 blockout = false parameter.integer("Speed", 0, 100, 0) m = true a = 0 w,h=spriteSize("Platformer Art:Block Grass") blockx = 0 blocky = 0 end -- This function gets called once every frame function draw() move = move + 5 background(46, 145, 216, 255) -- Center the camera on the boy character camPos = vec2(math.min(WIDTH/2 - boy.position.x, 140),HEIGHT/6) translate(camPos.x,camPos.y) -- Draw ground howMany = 999 for i = 1,howMany do sprite("Platformer Art:Block Grass",-WIDTH/2 - move - Speed + w*i, -115) end blockx = WIDTH -move Blocks:draw() Boy:draw() end


Boy = class() vert = 0 jump=false jumped=false jumping=false function Boy:init(x) -- you can accept and set parameters here self.x = x end jump=jumpHeight function Boy:draw() if jumping == false then sprite("Platformer Art:Guy Look Right",WIDTH/8, vert-35) else sprite("Platformer Art:Guy Jump",WIDTH/8, vert-35) end if CurrentTouch.state == BEGAN and jumps == true then sound( SOUND_JUMP , 1) end if CurrentTouch.state == BEGAN or CurrentTouch.state == MOVING then if jumped == false then jump=true jumping=true end end if jumped == true then Boy:down() end if jump == true then Boy:up() end end function Boy:up() vert = vert + 10 if vert >= 300 then jumped = true jump=false end end function Boy:down() vert = vert - 10 if vert <= 0 then vert = 0 jumped = false jumping = false end end function Boy:touched(touch) end


Blocks = class() function Blocks:init(x) -- you can accept and set parameters here self.x = x end function Blocks:draw() if m == true then a = math.random(10, 25) a = a / 10 m = false end milsec = milsec + 1 if milsec == 60*a then -- Draw blocks Blocks:layer() end sprite("Platformer Art:Block Grass", blockx, blocky) blocky = -115 + h while blockx < 0 do blockx = blockx - move end if blockx <= 0 then blockx = WIDTH end end function Blocks:layer() milsec = 0 m = true end function Blocks:touched(touch) -- Codea does not automatically call this method end function Blocks:blockdraw() end


  • GibGib
    Posts: 59

    Im at work (shhh) and dont have my ipad with me but one debugging trick I can suggest is to comment out your block class and any instatiation of it or references to it in your other code. Then run your project - is the boy still moving? If so most likely something in the block class. Caveate is I am new and my advice maybe BS :) But honestly I do this when debugging in any language.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    @TimurEke when you copy code do a long press on the project. Everthing is copied and it is easier to paste all in one in a new project. I cant test your project cause it is too long to copy paste the tabs individually...

  • dave1707dave1707 Mod
    Posts: 7,650

    Here is you problem. Once blockx gets below 0, you never exit the while loop.

        while blockx < 0 do         blockx = blockx - move     end
  • dave1707, thank you a lot!!!

  • Jmv38, ok I will do it in all my posts thank u

Sign In or Register to comment.