This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-10-30 05:19:48

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Fake Dictionaries?

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:

Code:

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:

Code:

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:

Code:

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.  smile

Offline

 

#2 2012-10-30 05:29:22

Gravitation
New Scratcher
Registered: 2012-09-26
Posts: 500+

Re: Fake Dictionaries?

That seems like the most efficient solution, Magnie.  smile

Offline

 

#3 2012-10-30 05:45:17

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Fake Dictionaries?

Gravitation wrote:

That seems like the most efficient solution, Magnie.  smile

Haha, okay, thanks!

I'll check again later today, see if anyone else might have a suggestion.

Offline

 

#4 2012-10-30 08:49:06

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Offline

 

#5 2012-10-30 10:50:30

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Fake Dictionaries?

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.  tongue

Offline

 

#6 2012-10-30 13:36:43

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Fake Dictionaries?

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,


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#7 2012-10-30 13:53:31

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Fake Dictionaries?

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.  tongue

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

 

#8 2012-10-30 19:19:16

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Fake Dictionaries?

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)


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#9 2012-10-31 00:40:05

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Fake Dictionaries?

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.  smile

Offline

 

#10 2012-10-31 02:45:23

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Fake Dictionaries?

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  tongue

Offline

 

#11 2012-10-31 07:59:00

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Fake Dictionaries?

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])


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#12 2012-10-31 10:35:54

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Fake Dictionaries?

It might make more sense to rather than use 40x36 squares use whole screen costumes, and have the adjacent squares load as well, 9 costumes for a 3x3 map, 16 for a 4x4 etc.


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#13 2012-10-31 19:28:01

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Fake Dictionaries?

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.  tongue

zammer990: Then I wouldn't be able to create random "high resolution" maps.  tongue

Offline

 

#14 2012-10-31 22:06:49

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Fake Dictionaries?

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])


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer