[Lua] Why are the wrong sectors being referenced when they shouldn't be?

This is a private early 3D version of Empiralist that you cannot download. Either the wrong textures or no textures are being used due to currentLine.frontsector and currentLine.backsector not pointing to the intended sector. I don't know why this is happening when it should be working fine.

Lua:
local function applyTextureToWalls(player, chunkCellOffsetY)
    if not player or not player.valid return end
    local pl_emp = player.empiralist
    if gametype == GT_EMPIRALIST and gamemap == empiralistMapNum and not mapEmpiralistDataProgressMode and pl_emp.chunkPreparationTime == TICRATE
        if chunkCellOffsetY < 0 or chunkCellOffsetY > 8192*FRACUNIT
            pl_emp.chunkPreparationTime = -TICRATE
        else
            local chunkCellX, chunkCellY
            for i = 1,#loadedWorldAreaChunks
                if loadedWorldAreaChunks[i] == pl_emp.worldArea*64+pl_emp.worldAreaChunk
                    if i == 1 or i == 5
                        chunkCellX = -8976*FRACUNIT
                    elseif i == 2 or i == 6
                        chunkCellX = -272*FRACUNIT
                    elseif i == 3 or i == 7
                        chunkCellX = 8432*FRACUNIT
                    elseif i == 4 or i == 8
                        chunkCellX = 17136*FRACUNIT
                    end
                    if i >= 1 and i <= 4
                        chunkCellY = 272*FRACUNIT+chunkCellOffsetY
                    elseif i >= 5 and i <= 8
                        chunkCellY = -8432*FRACUNIT+chunkCellOffsetY
                    end
                end
            end
            for realChunkCellX = chunkCellX,chunkCellX-(8192*FRACUNIT),-256*FRACUNIT
                local currentSubsector = R_PointInSubsectorOrNil(realChunkCellX, chunkCellY)
                if currentSubsector
                    for lineNum = 0,#currentSubsector.sector.lines
                        local currentLine = currentSubsector.sector.lines[lineNum]
                        if currentLine
                            if currentLine.backsector
                                if currentLine.frontsector.floorheight == currentLine.backsector.floorheight
                                    currentLine.frontside.bottomtexture = 0
                                    currentLine.backside.bottomtexture = 0
                                else
                                    local chunkCellXInt, chunkCellYInt
                                    if currentLine.frontsector.floorheight > currentLine.backsector.floorheight
                                        chunkCellXInt = (currentLine.frontsector.tag%32)+1
                                        chunkCellYInt = (currentLine.frontsector.tag/32)+1
                                    else
                                        chunkCellXInt = (currentLine.backsector.tag%32)+1
                                        chunkCellYInt = (currentLine.backsector.tag/32)+1
                                    end
                                    if worldAreas[pl_emp.worldArea] and type(worldAreas[pl_emp.worldArea]) == "table" and worldAreas[pl_emp.worldArea][pl_emp.worldAreaChunk] and type(worldAreas[pl_emp.worldArea][pl_emp.worldAreaChunk]) == "table"
                                        local currentWorldAreaChunk = worldAreas[pl_emp.worldArea][pl_emp.worldAreaChunk]
                                        if currentWorldAreaChunk[1] and type(currentWorldAreaChunk[1]) == "table"
                                            local currentWorldAreaChunkMap = currentWorldAreaChunk[1]
                                            if currentWorldAreaChunkMap[chunkCellYInt] and type(currentWorldAreaChunkMap[chunkCellYInt]) == "table" and currentWorldAreaChunkMap[chunkCellYInt][chunkCellXInt] and type(currentWorldAreaChunkMap[chunkCellYInt][chunkCellXInt]) == "string"
                                                local currentWorldAreaChunkMapCell = currentWorldAreaChunkMap[chunkCellYInt][chunkCellXInt]
                                                local _, wallPic = string.match(currentWorldAreaChunkMapCell, "(%w+),(%w+),(%d+)")
                                                local wallPicToUse = R_CheckTextureNumForName(wallPic)
                                                if wallPicToUse == -1
                                                    wallPicToUse = 0
                                                end
                                                if currentLine.frontsector.floorheight > currentLine.backsector.floorheight
                                                    currentLine.frontside.bottomtexture = 0
                                                    currentLine.backside.bottomtexture = wallPicToUse
                                                else
                                                    currentLine.frontside.bottomtexture = wallPicToUse
                                                    currentLine.backside.bottomtexture = 0
                                                end
                                            else
                                                currentLine.frontside.bottomtexture = 0
                                                currentLine.backside.bottomtexture = 0
                                            end
                                        else
                                            currentLine.frontside.bottomtexture = 0
                                            currentLine.backside.bottomtexture = 0
                                        end
                                    else
                                        currentLine.frontside.bottomtexture = 0
                                        currentLine.backside.bottomtexture = 0
                                    end
                                end
                            else
                                currentLine.frontside.bottomtexture = 0
                            end
                        end
                    end
                end
            end
            return applyTextureToWalls(player, chunkCellOffsetY+(256*FRACUNIT))
        end
    end
end

srb20001.png


Credit for fixing some minor issues with the thread goes to RapidGame7 for giving me some great message board advice on Discord.
Post automatically merged:

I figured out how to fix the issue, which involved making a new table, which is what I originally wanted to avoid, but it will make do since it is the best solution that actually works.

Lua:
local function applyTextureToWalls(player, chunkCellOffsetY)
    if not player or not player.valid return end
    local pl_emp = player.empiralist
    if gametype == GT_EMPIRALIST and gamemap == empiralistMapNum and not mapEmpiralistDataProgressMode and pl_emp.chunkPreparationTime == TICRATE
        if chunkCellOffsetY < 0 or chunkCellOffsetY > 8192*FRACUNIT
            pl_emp.chunkPreparationTime = -TICRATE
        else
            local chunkCellX, chunkCellY
            for i = 1,#loadedWorldAreaChunks
                if loadedWorldAreaChunks[i] == pl_emp.worldArea*64+pl_emp.worldAreaChunk
                    if i == 1 or i == 5
                        chunkCellX = -8976*FRACUNIT
                    elseif i == 2 or i == 6
                        chunkCellX = -272*FRACUNIT
                    elseif i == 3 or i == 7
                        chunkCellX = 8432*FRACUNIT
                    elseif i == 4 or i == 8
                        chunkCellX = 17136*FRACUNIT
                    end
                    if i >= 1 and i <= 4
                        chunkCellY = 272*FRACUNIT+chunkCellOffsetY
                    elseif i >= 5 and i <= 8
                        chunkCellY = -8432*FRACUNIT+chunkCellOffsetY
                    end
                end
            end
            for realChunkCellX = chunkCellX,chunkCellX-(8192*FRACUNIT),-256*FRACUNIT
                local currentSubsector = R_PointInSubsectorOrNil(realChunkCellX, chunkCellY)
                if currentSubsector
                    for lineNum = 0,#currentSubsector.sector.lines
                        local currentLine = currentSubsector.sector.lines[lineNum]
                        if currentLine
                            if currentLine.backsector
                                if currentLine.frontsector.floorheight == currentLine.backsector.floorheight
                                    currentLine.frontside.bottomtexture = 0
                                    currentLine.backside.bottomtexture = 0
                                else
                                    if currentLine.frontsector.floorheight > currentLine.backsector.floorheight
                                        currentLine.frontside.bottomtexture = 0
                                        currentLine.backside.bottomtexture = wallTextures[#currentLine.frontsector]
                                    else
                                        currentLine.frontside.bottomtexture = wallTextures[#currentLine.backsector]
                                        currentLine.backside.bottomtexture  = 0
                                    end
                                end
                            else
                                currentLine.frontside.bottomtexture = 0
                            end
                        end
                    end
                end
            end
            return applyTextureToWalls(player, chunkCellOffsetY+(256*FRACUNIT))
        end
    end
end
 
Last edited:

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top