Please help me with an error that.. seriously. I can't even.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Sosolol261
Party member
Posts: 125
Joined: Wed Nov 26, 2014 6:43 am

Please help me with an error that.. seriously. I can't even.

Post by Sosolol261 »

Hello lovers!!

I came across this weird(frustrating, ILLOGICAL) error which totally makes me insane.
So.. What I'm trying to do is:
  • Add a table in a table. The inserted table has an id value which is predetermined by another algorithm.
    Then run the main table through table.sort and sort it by Y > Z values.
    Then use the ID of each tile table to draw a map with depth.
My error is in step 1 and 2.. or even 3. Actually I don't even know where my error is.
Image
This is my error. It makes no sense since this is the sorting code:

Code: Select all

table.sort(self.mapData, function(a, b) return a.y < b.y or a.z < b.z end)
And a, b represent the tile tables which I added beforehand(step 1)

Code: Select all

	self.mapData = {}
	for layer = 1, #mapIO.map.layers do
		for pos = 1, mapIO.map.layers[layer].width * mapIO.map.layers[layer].height do
			local id = mapIO.map.layers[layer].data[pos]   -- a line I'll mention
			if id ~= 0 then
				-- x, y coordinates are being saved as iso coordinates
				x, y = mapToIso(pos)
				z = (layer - 1) / 2
				table.insert(self.mapData, {id = id, x = x, y = y, z = z})
			end
		end
	end
now. If I remove the mentioned layer, the error changes to:
Image
Line 63 adds the IDth quad to a spritesheet. It obviously errors since ERROR #2 THE VARIABLE ID IS 2049.
(I don't have a 2049th quad)
I NEVER SET THE GLOBAL VARIABLE ID IN MY CODE EVER BEFORE AND IT IS DESTOYING MY MENTAL HEALTH..
I also have no idea how it affects the table.sort function.
I'm attaching the love file at the bottom of the post so.. please give it a look and yeah.
Thank you for your help :)
Attachments
2DMashup.love
this.
(14.07 KiB) Downloaded 96 times
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Please help me with an error that.. seriously. I can't e

Post by pgimeno »

I think the "invalid order function" error refers to the comparison function not returning a consistent order criterion. For example, it may mean that a < b, b < c and c < a.

That can happen for these:

Code: Select all

a = { y = 2, z = 5 }
b = { y = 1, z = 7 }
c = { y = 2, z = 4 }
Note that:

Code: Select all

> print(a.y < b.y or a.z < b.z)
true
> print(b.y < c.y or b.z < c.z)
true
> print(c.y < a.y or c.z < a.z)
true
As for the second problem, one of the ids is "player", and you don't seem to have tiles["player"], so accessing tiles["player"].img throws an error. Maybe you intended to copy a table and instead modified it by reference?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 164 guests