grid = {}
blocks = {}
function grid.spawn( x,y,id )
blocks = {xy = {id = id}}
end
My prblem is that i want to place a variable inside a table name i.e. when function grid.spawn(1,2,3) gets called in love.load function, it should create a table inside "blocks" named "x1y2" and it would have a variable id = 3. I spent an hour trying to make it work or find on the internet how to do it, I failed and now i'm here posting this willing that someone will help. Thanks in advice.
P.S. Sorry if bad English
Thanks for a fast reply. I need to make a code that makes a table called "x1y2" (with letters x and y in the name). Why I need this? I want to make a sideway scrolling 2d platformer sort of that uses tiled maps. Map files would be made of a lot of grid.spawn(x,y,id) functions, when you load a map, it makes a lot of tables inside "blocks" table that have a "id" value in them. Draw function checks id's inside tables that are inside "blocks" and draws a corresponding image to the id in the coordinates of that table. Character movement is not gridlocked, player moves freely (movement allready done). Collisions would work like that: the collisions code gets characters coordinates, divides them by 32, floors them (by doing this the code gets the block that the character is standing in), checks if there's a block bellow that has a id > 0. If yes it doesn't let the character y coordinates get bellow the blocks that the character is standing on y * 32. THis will work on all directions. This is the way I understand of doing tiled game. Please, if you post a code, explain how it works.
This is much better, because the x and y-values are numbers and Robin's solution makes you treat them as numbers. Your solution means that you have to convert them into a string first.
Another aspect is that tables are Lua's implementation of arrays. A level is a matrix of tiles and thus an array of arrays. By using the index ['x2y23'] instead of [2][23] you use this in a rather unnatural way. You impose your own ordering instead of a natural number-based one.
Ultra7 wrote:This is the way I understand of doing tiled game.