Page 3 of 3
Re: class problem.
Posted: Fri Jan 28, 2011 4:38 pm
by TheBreadCat
leiradel wrote:TheBreadCat wrote:are you even listening?
What about you, are you listening? I've asked if you could post a .love file that reproduces the problem and you didn't even answer.
You won't get much help with this kind of attitude.
no i cant post it , its to messed up and i deleted the problem. ill try to make a version that simulates the old problem.
oh and sorry but personly its a bit messed up , so i was i little angry at the moment , sorry.
Re: class problem.
Posted: Fri Jan 28, 2011 4:43 pm
by TheBreadCat
here you go:
Code: Select all
__HAS_SECS_COMPATIBLE_CLASSES__ = true
local class_mt = {}
function class_mt:__index(key)
if rawget(self, "__baseclass") then
return self.__baseclass[key]
end
return nil
end
class = setmetatable({ __baseclass = {} }, class_mt)
function class:new(...)
local c = {}
c.__baseclass = self
setmetatable(c, getmetatable(self))
if c.init then
c:init(...)
end
return c
end
cCake = class:new()
function cCake:init()
self.x = 0
self.y = 0
self.hspeed = 0
self.vspeed = 0
end
function cCake:MoveUp()
self.y = self.y-1
end
function love.load()
cake = cCake
end
function love.update(dt)
cake:MoveUp()
end
and the error:
Code: Select all
attempt to perform arithmetic on field 'x'(a nil value)
Re: class problem.
Posted: Fri Jan 28, 2011 5:00 pm
by vrld
TheBreadCat wrote:Code: Select all
function love.load()
cake = cCake
end
That won't work. you have to make an instance of cCake:
Code: Select all
function love.load()
cake = cCake:new()
end
Re: class problem.
Posted: Fri Jan 28, 2011 6:27 pm
by TheBreadCat
vrld wrote:TheBreadCat wrote:Code: Select all
function love.load()
cake = cCake
end
That won't work. you have to make an instance of cCake:
Code: Select all
function love.load()
cake = cCake:new()
end
thanks but now there is one problem..
when i to to (ex.) add to varibles of the same instance , ill get an error.
Code: Select all
function cCake:Update()
self.x = self.x + self.hspeed
self.y = self.y + self.vspeed
self.hspeed = 0
self.vspeed = 0
end
Code: Select all
attempt to index local 'self'(a nil value)
Re: class problem.
Posted: Fri Jan 28, 2011 6:48 pm
by vrld
TheBreadCat wrote:Code: Select all
attempt to index local 'self'(a nil value)
From the code you posted it's hard to tell, but I think you might be calling Update() wrong. A variation of this was pointed out to you earlier many times. I suggest that you read this:
colon operator
Re: class problem.
Posted: Fri Jan 28, 2011 7:25 pm
by TheBreadCat
vrld wrote:TheBreadCat wrote:Code: Select all
attempt to index local 'self'(a nil value)
From the code you posted it's hard to tell, but I think you might be calling Update() wrong. A variation of this was pointed out to you earlier many times. I suggest that you read this:
colon operator
FINALLY thanks all of you!
after 2 days i can finally start making that game!
Re: *SOLVED*class problem.
Posted: Sat Jan 29, 2011 10:01 am
by BlackBulletIV
So it was the colon operator issue? Didn't I point that out before? Maybe I wasn't explicit enough.
Re: *SOLVED*class problem.
Posted: Tue Feb 01, 2011 8:50 am
by TheBreadCat
BlackBulletIV wrote:So it was the colon operator issue? Didn't I point that out before? Maybe I wasn't explicit enough.
i had to do some declariations in the init functions.