Messed up variable with connecting block textures
Posted: Sat May 25, 2024 7:42 pm
I'm making a tile-based platformer and have come into an issue.
For some reason, v and v2 both work perfectly fine, but v3 has just decided to not return true when checking its ID.
The possible IDs can only be 1 or 2 in this case, and you can see that v and v2 have no issues accessing them.
For reference, t is a table of Block Objects, state.worldW is unchangeably 32 and since the blocks are one table, adding this value basically moves the selected block down by 1 y level.
I'm curious if anyone knows why, since I can't see it being anything outside of this function, but I also have no idea what's causing it.
Lower values of state.worldW seem to work weirdly, like v3 = t[i+2] "works", but obviously it's wrong.
also this is my first time on the forum lol hi
For some reason, v and v2 both work perfectly fine, but v3 has just decided to not return true when checking its ID.
The possible IDs can only be 1 or 2 in this case, and you can see that v and v2 have no issues accessing them.
For reference, t is a table of Block Objects, state.worldW is unchangeably 32 and since the blocks are one table, adding this value basically moves the selected block down by 1 y level.
I'm curious if anyone knows why, since I can't see it being anything outside of this function, but I also have no idea what's causing it.
Lower values of state.worldW seem to work weirdly, like v3 = t[i+2] "works", but obviously it's wrong.
Code: Select all
function Block:update(t,state,dt)
-- check adjacencies and update self.merge
-- v (self)
for i = 1, #t do
local v = t[i]
local v2 = t[i+1]
-- FOR SOME REASON, THIS ISN'T INITIALISING IT
local v3 = t[i+state.worldW]
-- check if not edge of the world
if i % state.worldW ~= 0
-- check if v2 fits in the table
and i + 1 <= #t
-- compare v and v2
and v.id == v2.id then
if v.merge == 0
or v.merge == 1
or v.merge == 4
or v.merge == 5
or v.merge == 8
or v.merge == 9
or v.merge == 12
or v.merge == 13 then
v.merge = v.merge + 2
end
if v2.merge == 1 then
v2.merge = v2.merge + 8
else
v2.merge = 8
end
end
-- check if v3 fits in the table
if i + state.worldW <= #t
-- compare v and v3
and v.id == v3.id then -- <------ this never triggers, without this the below code works. everything above this works.
-- check if v is unmerged
if v.merge == 0
or v.merge == 1
or v.merge == 2
or v.merge == 3
or v.merge == 8
or v.merge == 9
or v.merge == 10
or v.merge == 11 then
v.merge = v.merge + 4
end
v3.merge = 1
end
end
end