Heya again... Just a few more (increasingly-stupid) questions! I'm sure at least one of these is covered elsewhere, but searching never brings anything seemingly-useful up for me...
1. If I were to make, for example, a list of items or spells or something for an RPG, would I be right in assuming this is best done via a Table? I'm familiar with Javascript, but that kind of data in JS was easiest to maintain in rather nice-looking arrays.
2. How would I go about /creating/ the entity data and tile data for a map (not image files, but the other stuff that goes with it)? I couldn't find anything more than "tile-based movement' and things like that when I would search for information on the wiki, so I had to ask...
Sorry, though, for the annoyance!
Lacking information
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Lacking information
Yes. Tables are similar to arrays.AWizardDidIt wrote:1. If I were to make, for example, a list of items or spells or something for an RPG, would I be right in assuming this is best done via a Table? I'm familiar with Javascript, but that kind of data in JS was easiest to maintain in rather nice-looking arrays.
I think you'll have to elaborate a bit here. What do you mean? Are you talking about creating a tilemap? If so, I suppose a 2-dimensional table would be what you were looking for, like Kikito explained in this thread: http://love2d.org/forums/viewtopic.php?f=4&t=1894AWizardDidIt wrote:2. How would I go about /creating/ the entity data and tile data for a map (not image files, but the other stuff that goes with it)? I couldn't find anything more than "tile-based movement' and things like that when I would search for information on the wiki, so I had to ask...
-
- Prole
- Posts: 14
- Joined: Wed Sep 16, 2009 9:55 am
Re: Lacking information
Thanks, for question 1's answer, anyway. As for question 2... You linked to a topic I started, and his answer about tile maps was more than satisfactory.
What I'm actually asking in Question 2 is more like... "I made a 2-dimensional table for a map, complete with three file-types and three entity placements just for practice. I have no data for the entities to correspond to, however, so there's no 'dialogue' or 'graphic'... or even an obstruction where the entities are placed. Basically, the entities don't exist yet. How do I go about creating those?" I figured I asked it well enough, but I suppose I worded it awkwardly?
Such information as I would imagine would go into an 'entity' would be things like "which graphic to load" (though I'm not even sure how would be best to format said graphic, I'm pretty sure I saw a tutorial about that which I'll check later, and I'll just use still-figure images for them for now) and other factors specific to certain entity types (like "damage on contact" or "Entity's HP" and the like).
I hope this helps, seriously... I'm awful at explaining these things.
What I'm actually asking in Question 2 is more like... "I made a 2-dimensional table for a map, complete with three file-types and three entity placements just for practice. I have no data for the entities to correspond to, however, so there's no 'dialogue' or 'graphic'... or even an obstruction where the entities are placed. Basically, the entities don't exist yet. How do I go about creating those?" I figured I asked it well enough, but I suppose I worded it awkwardly?
Such information as I would imagine would go into an 'entity' would be things like "which graphic to load" (though I'm not even sure how would be best to format said graphic, I'm pretty sure I saw a tutorial about that which I'll check later, and I'll just use still-figure images for them for now) and other factors specific to certain entity types (like "damage on contact" or "Entity's HP" and the like).
I hope this helps, seriously... I'm awful at explaining these things.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Lacking information
Tables are amazing.
Tables > Arrays
You can put anything in a table, including another table, functions, values, data like images and sounds, everything.
They're amazing.
Tables > Arrays
You can put anything in a table, including another table, functions, values, data like images and sounds, everything.
Code: Select all
table = {}
table = { something = whatever, more = function() doThis() end }
table.something = { more = stuff, yet = more }
table[3] = word
table["name"] = awesome
table["super"] = function(parameter) doThat() andThat(value) end
--Multidimensional Array
mda = {}
for x=1,100 do
mda[x] = {}
for y=1,100 do
mda[x][y] = {}
for z=1,100 do
mda[x][y][z] = value
end
end
end
--And so on...
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Lacking information
My favorite way to do tiles is like this:
What you're looking at is a table of tables. The table "map" contains rows, which contain the ID number of tiles (instead of an ID number, you could use an image, a table of data, etc.). This is an 8x8 map, but tables in Lua can be any size, so you could make it as big or small as you want.
Why do it like this? Because then you can use one of Lua's most useful features to its full advantage: For pairs in table. For example, to draw all of those tiles, this is all the code we'd need:
This works: For pairs in table is a kind of loop which operates once on every key/value pair in a given table. As you can see, we do this to the "map" table, and assign the variables "x" and "row" to the key and value it's iterating over. "x" is going to be a number, and "row" is going to be a table. The first pair will be, for example, 1 and {1,2,1,1,2,2,2,3}. So what do we do with this? We iterate over /that/ table, too, assigning numbers to "y" and "tile". The first pair will be 1 and 1.
Then drawing it is pretty simple. We set the position according to "x" and "y", and the image to use a graphic from the "tileimages" table (tileimages[1] is a grass tile, tileimages[2] is a sand tile, etc.).
That should get you started in the right direction. If you need more explanation, feel free to ask.
Code: Select all
tileimages = {
love.graphics.newImage("grass.png"),
love.graphics.newImage("sand.png"),
love.graphics.newImage("water.png"),
}
tilesize = 32
map = {
{1,2,1,1,2,2,2,3},
{1,1,1,2,2,2,3,3},
{1,1,1,2,2,3,3,3},
{1,1,2,2,2,2,3,3},
{1,1,2,2,2,2,3,3},
{1,1,1,1,2,2,2,3},
{1,1,2,1,2,2,3,3},
{1,1,1,1,2,2,3,3},
}
Why do it like this? Because then you can use one of Lua's most useful features to its full advantage: For pairs in table. For example, to draw all of those tiles, this is all the code we'd need:
Code: Select all
function love.draw()
for x, row in pairs(map) do
for y, tile in pairs (row) do
love.graphics.draw(tileimages[tile], x*tilesize, y*tilesize)
end
end
end
Then drawing it is pretty simple. We set the position according to "x" and "y", and the image to use a graphic from the "tileimages" table (tileimages[1] is a grass tile, tileimages[2] is a sand tile, etc.).
That should get you started in the right direction. If you need more explanation, feel free to ask.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
-
- Prole
- Posts: 14
- Joined: Wed Sep 16, 2009 9:55 am
Re: Lacking information [essentially resolved]
Well, Taehl, as I said... Kikito answered my "how to make a tilemap" question in my other thread. As for my previous question about entities and tables/etc, that's resolved now, I think... thanks, though!
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 5 guests