Help for automation of 2-dimensional grid table

Hi all,

I have been struggeling with this for several hours and i just cant understand why it shouldnt work (maybe its getting to late for programming).

my code looks like this:

mapsize = 4 --number of tiles in x-y direction [square map]  
griddata = {} --contains data for the grid griddata[1][1] eg.  
  
function grid()  
 for x=1, mapsize do  
 for y=1, mapsize do  
 griddata[x] = {} --Expand the table to have a y value   
 griddata[x][y] = (x .. "," .. y)  
end  
  
function test()  
 for x=1,mapsize do  
 for y=1,mapsize do  
 print(griddata[x][y])   
end  

The output of the test() is something like this:
nil
nil
nil
1,4
nil
nil
nil
2,4
nil
nil
nil
3,4
nil
nil
nil
4,4

What am i missing in understanding this issue? it should be so easy…

Thanks in advance [import]uid: 162464 topic_id: 29579 reply_id: 329579[/import]

Try something like this. I’ve been using this type of set up for the last 3 or 4 weeks on my project:

[lua]function grid()
for x=1, mapsize do
griddata[x] = {} – create the 1D table here outside of second for loop
for y=1, mapsize do
griddata[x][y] = (x … “,” … y)
end
end
end[/lua]

This took me a long time to figure out on my own so I help this expedites your process! :slight_smile: [import]uid: 105707 topic_id: 29579 reply_id: 118751[/import]

Haha, ofcause - having it inside the y-loop will erase/reset the y part everytime !!

Big thanks… now i can get back to programing further - the downtime did however produce some more assets :wink: [import]uid: 162464 topic_id: 29579 reply_id: 118752[/import]

Glad I could help. I’ve been doing a tile based map as well. In hindsight it’s really straightforward but putting it together for the first time took a lot of thinking for me. Feels awesome to whip something up that works :slight_smile: [import]uid: 105707 topic_id: 29579 reply_id: 118755[/import]

Indeed, just a question. The next im gonna implement is automatic movement of the map so the viewpoint somewhat follows the characther - hes more or less stays in the middle of the screen all the time. This should be ok easy program. But I would also like the map movement to stop as soon as there is no more map to display, but now allowing the character to move away from the center of the screen - so the viewpoint no longer follow him.

Have you done something like this? or what viewpoint behavoir are you using?

[import]uid: 162464 topic_id: 29579 reply_id: 118758[/import]

Great question… I’ve actually not unfortunately! Right now I’m just working on static maps that fit the size of the device screen.

I’ve actually been interested in pursuing this though for what’s next after this first project and had considered posting about it.

Is the strategy to shift every object uniformly in relation to the PC? That was the thought that had come to mind. If it is you could probably put a “max” and “min” limit on the shift in each direction that corresponds to the size of your overall map (with a buffer to keep the screen from going past the edge of the map). Once those thresholds are reached in any direction movement would switch from translating everything in relation to the character over to the character moving himself. Once the character came back from the threshold then the rest of the world would move again. What do you think of that?

It sounds very doable. A little bit tedious but also kind of awesome to solve as well. In fact, I bet you could do what I described fairly quickly (assuming you followed what I attempted to explain!)

Keep me posted on how you approach this! Would be interested to hear if anyone else from the community has insight on this.

[import]uid: 105707 topic_id: 29579 reply_id: 118765[/import]

This is basically the same idea that I also had.

I would be moving the map to make it look like the character is actually doing the walking. This is easily done as all small tile images are put into a imagegroup, so i can just move the group.

my map is large, like 2000px x 2000px, so when the maps reaches its edges the screen, the map should no longer move, instead the character now shifts position. But i have trouble identifying how my thresholds or triggers should be to allow this transition.

Wow, trying to get my idea down in words (talking with other ppl) actually helps me seeing the building steps i need to do, fantastic :wink:

It is a bit tedious, but also a challenge (at least for new developers), and i love these kind of challenges :wink: I’ll keep you updated- [import]uid: 162464 topic_id: 29579 reply_id: 118814[/import]

Yes, please keep me posted on your progress. As I said, I expect that I will attempt to solve the same challenge to extend the base capabilities I’m building into my current project.

Thanks for reminding me that imagegroup is a powerful asset in moving everything at once… that’s key! [import]uid: 105707 topic_id: 29579 reply_id: 118816[/import]

Ok, i have made the first draft for the panning function. I made it pretty much as we discussed.

If you want to try my compiled build, just send me an e-mail, ill share a dropbox folder with you… its not perfect, but functional…
Zwonkie@hotmail.com [import]uid: 162464 topic_id: 29579 reply_id: 118918[/import]