So for a game I want to make needs dictionaries to get data for a scrolling, randomly generated world. I need to be able to look for an x and y input (like 0x0y) and get a value ('grass', 'stone', 'water', etc). So something like this:
0x0y = stone 1x0y = stone 2x0y = stone 0x1y = stone 1x1y = grass 2x1y = stone 0x2y = stone 1x2y = stone 2x2y = stone
There are ways to fake dictionaries in Scratch, but most of them are inefficient and slow. I need something that can find the costume of a specific square as fast as possible in a list with about 1000 (maybe more) items in a list.
My original thought was to do something like this:
switch to costume (letter (x) of (item (y) of [world v] ))The list would contain something like this:
SSS SGS SSS
And then name the costumes by that letter, but that only supports 64 (or so) costumes, where I would like to have support for at least a couple different hundred. So I thought of just adding another letter (which supports 4096, perfect!):
switch to costume (join (letter (((x) * (2)) - (1)) of (item (y) of [world v] )) (letter ((x) * (2)) of (item (y) of [world v] )))The list would contain:
0S0S0S 0S0G0S 0S0S0S
It doubles the list size, but looks like my best solution. Since I want an even simpler method, I want your ideas. Do you guys have any brilliant solutions to my dictionary problem?
Just want to see if there are any solutions before I start scripting the project.
Offline
That seems like the most efficient solution, Magnie.
Offline
Gravitation wrote:
That seems like the most efficient solution, Magnie.
Haha, okay, thanks!
I'll check again later today, see if anyone else might have a suggestion.
Offline
You mean an array?
Offline
scimonster wrote:
You mean an array?
Yeah, that's basically what my work-a-round is for the dictionaries. Clearly my ideas in my original post aren't very original.
Offline
do you really need more than a standard character set? I mean ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!"£$%^&*()-=_+,.<>/?'@#~\|`¬[]{};: is quite a large character set, and since you only need 1 for each kind of environment, so the 100ish there would normally be enough.
IF you need more you can get windows alt codes(ò,≈,ß, etc) but I don't know how scratch would cope,
Offline
zammer990 wrote:
do you really need more than a standard character set? I mean ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!"£$%^&*()-=_+,.<>/?'@#~\|`¬[]{};: is quite a large character set, and since you only need 1 for each kind of environment, so the 100ish there would normally be enough.
IF you need more you can get windows alt codes(ò,≈,ß, etc) but I don't know how scratch would cope,
If you think about it, multiple different versions of the grass floor (spring/summer, autumn, winter, holiday specific, etc) and then the same for all the other floors (wood, stone, water, lava). Then you have houses and other buildings, special tiles for river banks and signs and everything else, it can really add up. Think of how many different blocks there are in Minecraft, that's about how many different tiles there will. There might even be more since I plan to have buildings in the game as well and then there is the interior of those buildings. But that's the reason why I would need so many characters for the costumes and why it would be much easier to use a dictionary rather than an array/list.
As for the special characters, they aren't the same on different operating systems (I use Linux, so if I use codes on here, it may not work on Windows and vice-versa).
Edit: And for clarity, I'm using a grid of squares (each square is 40 by 36 pixels), so the squares will "connect" to each other to create larger objects (the buildings).
Last edited by Magnie (2012-10-30 13:55:53)
Offline
You could use another list storing things like season, so you have 4 costumes, and a script like this
when gf clicked if <(item (relevant) of [list v]) = (1)> if <(season) = [1]> switch to costume [spring v] end if <(season) = [2]> switch to costume [summer v]// et al
Last edited by zammer990 (2012-10-30 19:19:56)
Offline
zammer990 wrote:
You could use another list storing things like season, so you have 4 costumes, and a script like this
when gf clicked if <(item (relevant) of [list v]) = (1)> if <(season) = [1]> switch to costume [spring v] end if <(season) = [2]> switch to costume [summer v]// et al
That's true. Though I still need the hundred or more costumes keys.
Offline
I don't quite get your intent. So you want to make an array of blocks (are you generating it by code or manually?) and are the costumes... wait. I don't get it at all.
Magnie wrote:
(each square is 40 by 36 pixels)
That's not quite a square
Offline
The best way is to store it like this:
0x0y 1x0y 2x0y 0x1y 1x1y 2x1y ...
And retrieve like this:
(item (((x)*(width -- 3 in this case))+((y)+(1))) of [list v])
Offline
Hardmath123: Thank you, even though it took a moment or two to understand what you meant by "width". Your idea looks like the best option, now I don't have to worry about weird costume names.
zammer990: Then I wouldn't be able to create random "high resolution" maps.
Offline
Hardmath123 wrote:
The best way is to store it like this:
Code:
0x0y 1x0y 2x0y 0x1y 1x1y 2x1y ...And retrieve like this:
(item (((x)*(width -- 3 in this case))+((y)+(1))) of [list v])
don't you mean this?
(item (((y)*(width))+((x)+(1))) of [list v])
Offline