1

I'm turning a 2D rendered map which is unorganised into a string table, EG from:

"Render = {{Image,50,60,2}}"

Where Image is the image (I'm using Love2D Lua framework) 50 is the X axis 60 is the Y axis 2 is the Image ID (This is what will be in the actual table.)

But there's like 100 of these, all unorganised and stuff, and I need to oragnise them into a structured map.

Here's the odd bit: When I morph it into an organised string.. It.. Kinda rotates the table on a 90* angle anticlockwise.

Saying I want the result of

{ 
{7,6,5}, 
{6,5,4}, 
} 

I would get:

{ 
{5,4}, 
{6,5}, 
{7,6}, 
} 

Obviously no error since it technically works, just rotates wrongly. Here's the relevant code:

function OrganiseRenderIntoMap() 
    MapString = "" 

    Map2 = {} 
    MaxSoFarX = 0 
    MaxSoFarY = 0 
    for _,v in pairs(Render) do 
        if v[2] > MaxSoFarX then 
            MaxSoFarX = v[2] 
        elseif v[3] > MaxSoFarY then 
            MaxSoFarY = v[3] 
        end 
    end 

    for currx = 0, MaxSoFarX, 32 do 
        Map2[currx] = {} 
        MapString = MapString.."{" 
        for curry = 0, MaxSoFarY, 32 do 
            MapString = MapString..GetRenderPos(currx,curry).."," 
            Map2[currx][curry] = GetRenderPos(currx,curry) 
        end 
        MapString = MapString.."},\n" 
    end 

    return MapString 
end 


function GetRenderPos(locx,locy) 
    for _,v in pairs(Render) do 
        if v[2] == locx and v[3] == locy then 
            return v[4] 
        end 
    end 
end 
1
  • Unrelated note: you use a lot of global variables in your code (variables are global in Lua by default). Also, it would be easier to answer if you will fix your code so it would actually run in standalone Lua interpreter. Commented Mar 27, 2011 at 23:31

1 Answer 1

3

Give a look at my LÖVE tile tutorial. Section 1d-Strings speaks about how to handle the "switched x and y" problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I should've realised you'd access a map stored in a table via y before x. Silly me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.