[SOLVED] Tiled map generator problems

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
furi
Citizen
Posts: 73
Joined: Sat Feb 26, 2011 8:15 pm

[SOLVED] Tiled map generator problems

Post by furi »

*fixed*
by myself. :awesome:...
Despite the fact that the generator isn't necessarily the cleanest, best-looking one ever, I got it done. That's an accomplishment quite big for me.
Attachments
screenshot6.png
screenshot6.png (6.31 KiB) Viewed 1607 times
Last edited by furi on Fri Mar 04, 2011 4:11 pm, edited 3 times in total.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Tiled map generator problems

Post by kikito »

You have had lots of issues with tiles lately.

I can't debug your code just now, but I'm going to leave my tile tutorial link here in case it helps you:

https://github.com/kikito/love-tile-tutorial

It handles the things you are trying to do (tiles encoded inside a multi-line string) in a very straightforward way.

Regards!
When I write def I mean function.
User avatar
furi
Citizen
Posts: 73
Joined: Sat Feb 26, 2011 8:15 pm

Re: Tiled map generator problems

Post by furi »

kikito wrote:You have had lots of issues with tiles lately.

I can't debug your code just now, but I'm going to leave my tile tutorial link here in case it helps you:

https://github.com/kikito/love-tile-tutorial

It handles the things you are trying to do (tiles encoded inside a multi-line string) in a very straightforward way.

Regards!
Hey, thanks. I'll look into it.

EDIT: Oh, yeah, by the way: It's not necessarily drawing the tiles that's the problem. It's generating them accordingly.

You see...

Code: Select all

#####
#...#
#...#
#...#
#####
this? This is a 5x5 block. I have to generate maps that contain randomized 5x5 blocks (check the "grids" table above) that fill up the map. With the linear way text works, though, it's a real hassle.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Tiled map generator problems

Post by kikito »

I think you might be using the wrong tool for the job.

Strings are easy to edit, but difficult to work with. Specially in Lua.

Tables are easier to work with, but difficult to edit (or I'd say less easy to modify than strings).

Solution: Put your data into strings, but transform it into tables as soon as it leaves the "editable zone". If you need to, transforming a table into a string isn't that complicated (using table.concat really helps there).
When I write def I mean function.
User avatar
furi
Citizen
Posts: 73
Joined: Sat Feb 26, 2011 8:15 pm

Re: Tiled map generator problems

Post by furi »

kikito wrote:I think you might be using the wrong tool for the job.

Strings are easy to edit, but difficult to work with. Specially in Lua.

Tables are easier to work with, but difficult to edit (or I'd say less easy to modify than strings).

Solution: Put your data into strings, but transform it into tables as soon as it leaves the "editable zone". If you need to, transforming a table into a string isn't that complicated (using table.concat really helps there).
I'll try. I'm not the most experienced with tables, though. Thanks, anyways.

EDIT:

Code: Select all

gen={};
mapg2=string.gsub(mapg,"\n","");
x = -1;
for s in mapg2:gmatch"." do
	x = x + 1;
	y = muldown(x,mapx/5);
	for yy=0,4 do
		for xx=0,4 do
			table.insert(gen[y*5+yy],x*5+xx,grids[s+0]) --[y*5+yy]
		end
	end
end
Table expected, got nil.
I'm really not sure how to fix this.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Tiled map generator problems

Post by tentus »

furi wrote:
kikito wrote:I think you might be using the wrong tool for the job.

Strings are easy to edit, but difficult to work with. Specially in Lua.

Tables are easier to work with, but difficult to edit (or I'd say less easy to modify than strings).

Solution: Put your data into strings, but transform it into tables as soon as it leaves the "editable zone". If you need to, transforming a table into a string isn't that complicated (using table.concat really helps there).
I'll try. I'm not the most experienced with tables, though. Thanks, anyways.

EDIT:

Code: Select all

gen={};
mapg2=string.gsub(mapg,"\n","");
x = -1;
for s in mapg2:gmatch"." do
	x = x + 1;
	y = muldown(x,mapx/5);
	for yy=0,4 do
		for xx=0,4 do
			table.insert(gen[y*5+yy],x*5+xx,grids[s+0]) --[y*5+yy]
		end
	end
end
Table expected, got nil.
I'm really not sure how to fix this.
Shouldn't gmatch be a function?

Code: Select all

mapg2:gmatch(".")
In general, I would advise being internally consistent with how you use string functions. If you use mapg2:gmatch(".") in your for loop, it would generally be a good idea to also use mapg2=mapg.gsub("\n","") two lines earlier, just so that you don't confuse yourself down the road. Hope that makes sense.

Also, s+0 is kinda odd, you can just use s.
Last edited by tentus on Fri Mar 04, 2011 5:43 pm, edited 1 time in total.
Kurosuke needs beta testers
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Tiled map generator problems

Post by bartbes »

tentus wrote: Shouldn't gmatch be a function?

Code: Select all

mapg2:gmatch(".")
--is equal to
mapg2:gmatch "."
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Tiled map generator problems

Post by tentus »

bartbes wrote:
tentus wrote: Shouldn't gmatch be a function?

Code: Select all

mapg2:gmatch(".")
--is equal to
mapg2:gmatch "."
Huh, I did not know that. Is gmatch "." equivalent to gmatch"." ? (His does not have the space yours does).
Kurosuke needs beta testers
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: [SOLVED] Tiled map generator problems

Post by bartbes »

Yes, whitespace barely plays any role in lua's syntax.

Anyway, let me explain this trickery: when there's a single argument, and that argument is a literal of either a string or a table ("literal table" meaning {stuff}, not a variable name), the parentheses aren't needed. (so, ipairs{1, 2, 3} is valid as well).
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: [SOLVED] Tiled map generator problems

Post by tentus »

bartbes wrote:Yes, whitespace barely plays any role in lua's syntax.

Anyway, let me explain this trickery: when there's a single argument, and that argument is a literal of either a string or a table ("literal table" meaning {stuff}, not a variable name), the parentheses aren't needed. (so, ipairs{1, 2, 3} is valid as well).
Good to know! Man, I'm learning all kinds of stuff today.

So in the case of a two argument function (if he hadn't used mapg2: but instead gone with string. ) the trickery wouldn't have worked, right? And I assume that the same trick doesn't work with boolean or number arguments, since you didn't list them?
Kurosuke needs beta testers
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests