Howdy, Stranger!

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

Need help!

edited January 2014 in General Posts: 116

Why its an error at 44th line in class charx? I dont understand that! To look the error tap twice at the left side of the screen

Tagged:

Comments

  • edited January 2014 Posts: 116

    Oops i forgot the code here it is:


    --# Main -- lol -- Use this function to perform your initial setup function setup() parameter.integer("lol",0,1000,500 ) parameter.integer("y",-1,1,1) wall = Wall(50) char = Char(50,48,50,50,0,0,y) charx = CharX(WIDTH - wall.width - 48,100,50,50,0,0) block = Block(WIDTH,48,50,50,0,y) blockx = BlockX(WIDTH - wall.width - 50 + 2, HEIGHT,50,50,0,x) start = Start(WIDTH/2, HEIGHT/2, 200, 75) ground = Ground(50) timer = false vert = true print("touch to start") end function draw() --print(charx.x) wall.x = lol char.side = y block.side = y charx.side = x blockx.side = x background(40, 40, 50) if timer == true then if vert == true then ground:draw() char:draw() block:draw() block.x = block.x - 3 block.y = ground.y + 48 if char.y <= ground.y + ground.height -3 then char.y = ground.y + ground.height -2 char.tappedj = false char.speed = 0 char.a = true end else wall:draw() charx:draw() blockx:draw() blockx.y = blockx.y - 3 blockx.x = WIDTH - wall.width-50+2 if charx.side == 0 then if charx.x >= wall.x - wall.width + 3 then charx.x = wall.x - wall.width +2 charx.tappedj = false charx.speed = 0 charx.a = true end else if charx.x <= wall.x + wall.width -3 then charx.x = wall.x + wall.width -2 charx.tappedj = false charx.speed = 0 charx.a = true end end end end if timer == false then -- text("Tap anywhere to start", WIDTH/2, HEIGHT/2) -- fill(255, 255, 255, 255) -- font("Inconsolata") -- fontSize(500) start:draw() if CurrentTouch.state == BEGAN then start:touched(CurrentTouch) end end if CurrentTouch.x < WIDTH/2 and CurrentTouch.state == BEGAN then if vert == true then --while block.y <= -51 do --ground.y = ground.y - 3 --block.y = block.y - 3 --char.y = char.y -3 --end vert = false else --while block.y >= -51 do --ground.y = ground.y - 3 --block.y = block.y - 3 --char.y = char.y -3 --end vert = true end end end function gameOver() timer = false print("Game Over!") print("Tap to restart") block.x = WIDTH end --# Char Char = class() function Char:init(x,y,w,h,a,s,sd) -- you can accept and set parameters here self.x = x self.y = y self.width = w self.height = h self.angle = a self.speed = s self.acc = 0.3 self.tappedj = false self.a = true self.side = sd end function Char:draw() rect(self.x,self.y,self.width,self.height) rotate(self.angle) fill(255,255,255) smooth() noStroke() self.y = self.y + (self.speed * self.side) if self.speed == 0 then self.y = ground.y - ((self.width +2) * self.side) end if CurrentTouch.x > WIDTH/2 and CurrentTouch.state == BEGAN then if self.a == true then self.speed = 13 * self.side self.a = false end self.tappedj = true end if self.tappedj == true then self.speed = self.speed - (self.acc * self.side) end --if (self.x > block.x and self.x < block.x + block.width) or (self.x < block.x + block.width - self.width and self.x > block.x - self.width) then --if self.y < block.y + block.height then --gameOver() --end --end end function Char:touched(touch) -- Codea does not automatically call this method end --# Block Block = class() function Block:init(x,y,w,h,a,sd) -- you can accept and set parameters here self.x = x self.y = y self.width = w self.height = h self.angle = a self.side = sd end function Block:draw() rect(self.x,self.y,self.width,self.height) rotate(self.angle) fill(255,255,255) smooth() noStroke() if self.x <= -50 then self.x = WIDTH -- * math.random(3) end end function Block:touched(touch) -- Codea does not automatically call this method end --# Ground Ground = class() function Ground:init(h) -- you can accept and set parameters here self.x = 0 self.y = 0 self.width = WIDTH self.height = h self.angle = 0 end function Ground:draw() self.width = WIDTH rect(self.x,self.y,self.width,self.height) rotate(self.angle) fill(255,255,255) smooth() noStroke() end function Ground:touched(touch) -- Codea does not automatically call this method end --# CharX CharX = class() function CharX:init(x,y,w,h,a,s) -- you can accept and set parameters here parameter.integer("xx", -1,0,0) self.side = xx self.x = x self.y = y self.width = w self.height = h self.angle = a self.speed = s self.acc = 0.3 self.tappedj = false self.a = true self.lastSide = self.side end function CharX:draw() rect(self.x,self.y,self.width,self.height) rotate(self.angle) fill(255,255,255) smooth() noStroke() accSide() self.x = self.x - self.speed if self.speed == 0 then self.x = wall.x - self.width - self.width * self.side - wall.width * self.side --stay on wall end if CurrentTouch.x > WIDTH/2 and CurrentTouch.state == BEGAN then if self.a == true then self.speed = side(self.side) * 13 self.a = false end self.tappedj = true end if self.tappedj == true then self.speed = self.speed - self.acc --jump acc end end function accSide() self.lastSide = self.side self.side = self.xx if not self.lastSide == self.side then self.acc = self.acc * side(self.side) end end --if (self.y > block.y and self.y < block.y + block.height) or (self.y < block.y + block.height - self.height and self.y > block.y - self.height) then --if self.x > block.x - block.width then --gameOver() --end --end function side(b) if b == 0 then b = 1 else b = -1 end return(b) end function CharX:touched(touch) -- Codea does not automatically call this method end --# BlockX BlockX = class() function BlockX:init(x,y,w,h,a,sd) -- you can accept and set parameters here self.x = x self.y = y self.width = w self.height = h self.angle = a self.side = sd end function BlockX:draw() self.x = wall.x - self.width +2 rect(self.x,self.y,self.width,self.height) rotate(self.angle) fill(255,255,255) smooth() noStroke() if self.y <= -50 then self.y = HEIGHT -- * math.random(3) end end function BlockX:touched(touch) -- Codea does not automatically call this method end --# Wall Wall = class() function Wall:init(w) -- you can accept and set parameters here self.x = w self.y = 0 self.width = 50 self.height = HEIGHT end function Wall:draw() rect(self.x,self.y,self.width,self.height) fill(255,255,255) smooth() stroke(255, 255, 255, 255) strokeWidth(8) end function Wall:touched(touch) end --# Start Start = class() function Start:init(x,y,w,h) -- you can accept and set parameters here self.x = x self.y = y self.width = w self.height = h end function Start:draw() -- Codea does not automatically call this method sprite("Cargo Bot:Dialogue Box",self.x,self.y,self.width,self.height) text("Play", self.x + self.width/2, self.y + self.height/2) end function Start:touched(touch) -- Codea does not automatically call this method timer = true end
  • dave1707dave1707 Mod
    edited January 2014 Posts: 7,520

    @TimurEke Should accSide() and side() be Charx:accSide() and Charx:side(). Also in accSide(), you have self.xx which I think should be self.x . In the function draw(), x is nil and is being moved into charx.side.

  • Posts: 116

    No, self.xx is a parameter

  • dave1707dave1707 Mod
    Posts: 7,520

    @TimurEke I did a search for self.xx and the only reference to it that I found was self.side=self.xx . So it looks like nothing is ever moved into self.xx which makes it have a value of "nil". I saw a parameter "xx", but that gets moved into self.side in CharX:init().

Sign In or Register to comment.