Me again, this time it wont be as easy as choosing the right file loading function :v
Basically, to handle game objects, I have decided that objects had a prototype class (like actor or item), a defined template to copy (such as wall, enemy, player, door, gun, etc) that would define it's behavior and the object's attribute, and then a proper instance created via the template's spawn() function.
The prototype classes uses mixins that contain code for movement and drawing, both dependent on a mixin defining their grid based behavior.
The problem appears when I try to have each cell of my grid draw their contents : there seems to be no errors with objects of instance item, but for objects of instance actor, it just cannot find the reference to the current map passed during it's creation and throws an error when entering the drawing mixin.
Print() debugs have shown that the only actor created in the game.lua main loop, player, knows what his map is. (print(player.map.name) outputs "testmap" as intended)
I think the problem comes from mixins, but I am not sure. Could someone more well versed help me find my error ? (Also, obviously, if I am coding useless/ugly things, that is not the problem :p)
dat love file
Keep in mind that those pitiful stubs of documentation are meaningless since I began rewriting the way I manage everything, so do not rely on them :v
Confusion with mixins and missing variables
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Confusion with mixins and missing variables
after inserting the following line into Module_Mapped_Drawable:draw
i get the following output:
This means the last call was not from an instance, but on the class itself?
If you then change the function a second time:
you get the following stack trace:
source/cell.lua:77: in function 'drawContents' is as follows:
so the error must be in setting self.contents.actor.
a global search for 'self.contents.actor = ' found a match in source/cell:65
Is the third line that what you indended to do? Setting self.contents.actor to the actor class?
I hope this serves as a creative guide for future debugging!
Code: Select all
function Module_Mapped_Drawable:draw()
print("draw", self, self.map)
[...]
end
Code: Select all
draw instance of class item instance of class map
[...]
draw instance of class item instance of class map
draw class actor nil
If you then change the function a second time:
Code: Select all
function Module_Mapped_Drawable:draw()
print("draw", self, self.map)
if tostring(self) == "class actor" then error() end
[...]
end
Code: Select all
Error: nil
stack traceback:
[C]: in function 'error'
source/modules/drawable.lua:17: in function 'draw'
source/cell.lua:77: in function 'drawContents'
source/map.lua:96: in function 'draw'
source/game.lua:41: in function 'draw'
[string "boot.lua"]:438: in function <[string "boot.lua"]:399>
[C]: in function 'xpcall'
Code: Select all
if self.contents.actor then self.contents.actor:draw() end
a global search for 'self.contents.actor = ' found a match in source/cell:65
Code: Select all
--tells the cell which actor is inside it
function cell:setContent(content)
if content:isInstanceOf(actor) then
self.contents.actor = actor
end
if content:isInstanceOf(item) then
table.insert(self.contents.items, content)
end
end
I hope this serves as a creative guide for future debugging!
Xeldas Saga - my ca. 10min action-platformer (contains sound effects, music, graphics and a boss fight)
Re: Confusion with mixins and missing variables
Haha yes, I was just going to post about how I had found what my error was, and it indeed came from the line you highlighted
I had forgot that setContent's parameter was not "actor" anymore but just "content", as I added support for the item class, so it indeed added the actual class as the actor for that cell :v
Thanks for helping, your post will actually help me debug a lot !
I had forgot that setContent's parameter was not "actor" anymore but just "content", as I added support for the item class, so it indeed added the actual class as the actor for that cell :v
Thanks for helping, your post will actually help me debug a lot !
Who is online
Users browsing this forum: Bing [Bot], bostonstrong567, Google [Bot] and 6 guests