Howdy, Stranger!

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

How keep codea happy?

edited September 2014 in Questions Posts: 175

Hi, guys. Sorry for noob questions from me, but whats wrong in this piece of code?

Fishes = class()

function Fishes:init()
    -- you can accept and set parameters here
    self.fish = physics.body(CIRCLE,20)
    self.fish.x = 100
    self.fish.y = 0
end

function Fishes:draw()
   ellipse(self.fish.x,self.fish.y,40) -- this string makes codea unhappy
end

function Fishes:touched(touch)
    -- Codea does not automatically call this method
end

I expect codea dont like this values : "self.fish.x and self.fish.x"

http://s28.postimg.org/xjccmfpd9/IMG_0073.png

Tagged:

Comments

  • Jmv38Jmv38 Mod
    Posts: 3,295

    works fine for me
    i assume you wrote

        f.draw()
    

    instead of

        f:draw()
    
  • edited September 2014 Posts: 175

    @Jvm38 Im foregin and sometimes i understand your advices like slowpoke,but what you mean?

  • Jmv38Jmv38 Mod
    edited September 2014 Posts: 3,295
    do you see the '.' instead of ':'
    

    i suppose you made a typo mistake when calling the draw().
    This is very common when you begin with lua...

  • @Jvm38 no. I understand this. But problem in something else

  • Jmv38Jmv38 Mod
    Posts: 3,295

    then post the whole code, what you have posted works fine.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    btw, what do you mean 'makes codea unhappy'? can you post the error text?

  • Jmv38Jmv38 Mod
    Posts: 3,295

    PS: sorry for my short answers, i hope you dont feel this as rudeness. I just try to be quick and concise.

  • @Jvm38


    --# Main -- Kraken -- Use this function to perform your initial setup displayMode(FULLSCREEN) function setup() w = WIDTH/2 h = HEIGHT/2 xb = w xs = h xch = 270 xch = xch + 1 count = 1 floor = physics.body(EDGE,vec2(-WIDTH,0),vec2(WIDTH,0)) physics.pause() grav = physics.gravity(Gravity) ship = physics.body(CIRCLE,89) ship.y = h+199 ship.restitution = 1 end function touched(touch) if touch.state == ENDED then physics.resume() end end function outofscreen() if xb > w then xb = 0 count = count + 1 elseif xb < w then xb = 0 end if xs > w then xs = -20 end end function draw() xch = xch + 1 -- if touch.state == ENDED then -- ship.y = grav.y -- end pushStyle() sprite("Documents:backgroundblur",w,h) sprite("Documents:waveback",w-200,h+300) sprite("Documents:waveback",w+250,h+300) sprite("Documents:ship(vlad dont like this)",xch,ship.y,270,178) sprite("Documents:wavefrontbig",w,h+280) -- sprite("Documents:wavefront",w+440,h+290) popStyle() Fishes:draw() end --# Fishes Fishes = class() function Fishes:init() -- you can accept and set parameters here self.fish = physics.body(CIRCLE,20) self.fish.x = 100 self.fish.y = 0 end function Fishes:draw() ellipse(self.fish.x,self.fish.y,40) end function Fishes:touched(touch) -- Codea does not automatically call this method end
  • Jmv38Jmv38 Mod
    Posts: 3,295

    this makes no sense:

    draw()
        Fishes:draw()
    end
    

    Fishes is a class, not an instance of the class, you must create and draw one sample fish1 or more:


    --# Main -- Kraken -- Use this function to perform your initial setup displayMode(FULLSCREEN) function setup() w = WIDTH/2 h = HEIGHT/2 xb = w xs = h xch = 270 xch = xch + 1 count = 1 floor = physics.body(EDGE,vec2(-WIDTH,0),vec2(WIDTH,0)) physics.pause() grav = physics.gravity(Gravity) ship = physics.body(CIRCLE,89) ship.y = h+199 ship.restitution = 1 fish1 = Fishes() end function touched(touch) if touch.state == ENDED then physics.resume() end end function outofscreen() if xb > w then xb = 0 count = count + 1 elseif xb < w then xb = 0 end if xs > w then xs = -20 end end function draw() xch = xch + 1 -- if touch.state == ENDED then -- ship.y = grav.y -- end pushStyle() sprite("Documents:backgroundblur",w,h) sprite("Documents:waveback",w-200,h+300) sprite("Documents:waveback",w+250,h+300) sprite("Documents:ship(vlad dont like this)",xch,ship.y,270,178) sprite("Documents:wavefrontbig",w,h+280) -- sprite("Documents:wavefront",w+440,h+290) popStyle() fish1:draw() end --# Fishes Fishes = class() function Fishes:init() -- you can accept and set parameters here self.fish = physics.body(CIRCLE,20) self.fish.x = 100 self.fish.y = 0 end function Fishes:draw() ellipse(self.fish.x,self.fish.y,40) end function Fishes:touched(touch) -- Codea does not automatically call this method end
  • @Jvm38 thank you very much

Sign In or Register to comment.