2

I am making an 2D mining game, and i want to draw the map with two for loops. It would look something like this:

for(int y = 0; y < height; y++){
    for(int x = 0; x < width; x++){
        //create map chunk
    }
}

I know that is incorrect syntax for lua (it is actually c++ syntax). I don't know if there is a way to use for loops like this in lua. Also if there is another way to accomplish the same task without manually drawing out each chunk, that would be very helpful. Thanks

1 Answer 1

2

You can use numeric for loop.

for y=1,height do
    for x=1,width do
        -- create map chunk
    end
end

Note that I started counding from 1. Lua's numeric for includes the last value, i.e. height/width will be reached. And Lua normally indexes arrays starting from 1, not from 0.

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

1 Comment

Thanks! that is exactly the type of thing that i was looking for.

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.