Hi there!
So, I have function call to construct a building on a selected tile. Each tile has an entity variable, and an entity can be initialized as a building (as a subclass of entity). However, when I build a building on a selected tile, all previous buildings turn to the building type I choose.
Say we have two houses (first picture), then place a church (second picture). The houses get overwritten!
https://love2d.org/imgmirrur/3AkfGD5.html
It won't let you overwrite houses if you try to build in a spot that already has a building, so I guess that's good. In addition, tiles that have been previously selected - but not built on - are not affected.
I have to assume I'm doing something wrong with middleclass: https://github.com/kikito/middleclass.
(SOLVED) Objects of the same class are getting changed to the same object
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 7
- Joined: Sat Feb 05, 2022 12:46 am
(SOLVED) Objects of the same class are getting changed to the same object
- Attachments
-
- tile.lua
- (5.39 KiB) Downloaded 76 times
-
- entity.lua
- (1.42 KiB) Downloaded 72 times
-
- buildings.lua
- (3.14 KiB) Downloaded 80 times
Last edited by thedarkloon on Mon Feb 07, 2022 8:21 pm, edited 2 times in total.
Re: (Middle Class) Objects of the same class are getting changed to the same thing
Code: Select all
if tileIndex.sprite ~= nil then
love.graphics.draw(tileSetSheet, tileIndex.sprite, x, y)
if tileIndex.entity ~= nil then
love.graphics.draw(tileIndex.entity.sprite, x, y)
end
else
love.graphics.draw(tileSetSheet, TileQuads['E'], x, y)
end
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
-
- Prole
- Posts: 7
- Joined: Sat Feb 05, 2022 12:46 am
Re: (Middle Class) Objects of the same class are getting changed to the same thing
Yes. On second though it'd probably be better to not nest the entity draw. Thanks for pointing that out!
You'll find a lot of this code is... not great. Hence the buildings all changing.
You'll find a lot of this code is... not great. Hence the buildings all changing.
-
- Prole
- Posts: 7
- Joined: Sat Feb 05, 2022 12:46 am
Re: Objects of the same class are getting changed to the same object
Solved it! For some reason, building being a subclass of entity made it to where a new building call affected all buildings. By separating building and making it its own class and putting it in the same file as its data, the buildings are now their own objects.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 10 guests