*fixed*
by myself. ...
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.
[SOLVED] Tiled map generator problems
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] Tiled map generator problems
Last edited by furi on Fri Mar 04, 2011 4:11 pm, edited 3 times in total.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Tiled map generator problems
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!
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.
Re: Tiled map generator problems
Hey, thanks. I'll look into it.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!
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
#####
#...#
#...#
#...#
#####
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Tiled map generator problems
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).
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.
Re: Tiled map generator problems
I'll try. I'm not the most experienced with tables, though. Thanks, anyways.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).
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
I'm really not sure how to fix this.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Tiled map generator problems
Shouldn't gmatch be a function?furi wrote:I'll try. I'm not the most experienced with tables, though. Thanks, anyways.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).
EDIT:
Table expected, got nil.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
I'm really not sure how to fix this.
Code: Select all
mapg2:gmatch(".")
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
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Tiled map generator problems
tentus wrote: Shouldn't gmatch be a function?
Code: Select all
mapg2:gmatch(".")
--is equal to
mapg2:gmatch "."
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Tiled map generator problems
Huh, I did not know that. Is gmatch "." equivalent to gmatch"." ? (His does not have the space yours does).bartbes wrote:tentus wrote: Shouldn't gmatch be a function?Code: Select all
mapg2:gmatch(".") --is equal to mapg2:gmatch "."
Kurosuke needs beta testers
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: [SOLVED] Tiled map generator problems
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).
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).
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: [SOLVED] Tiled map generator problems
Good to know! Man, I'm learning all kinds of stuff today.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).
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
Who is online
Users browsing this forum: No registered users and 7 guests