ID:1505508
 
(See the best response by Lugia319.)
Problem description: Hey, so I'm using a system of assigning an icon_state to an obj in game. It's a Match game, where you have to match two objects on screen.

Now the problem is, the list I'm using is going to be really long, due to having the most of the functions down.

Code:
list/choices = list("blue", "blue", "blue", "blue", "red", "red", "red", "red", "orange", "orange", "orange", "orange", "yellow", "yellow", "yellow", "yellow") //As you can imagine, doing this as I increase map size will be annoying and inefficient.

list/choices = list("blue" = 4, "red" = 4, "orange" = 4, "yellow" = 4) //I want it to be more along the size of this. But I'm unsure of how this, or anything like this would work


//"Tile Assignment" as I like to call it.

proc
tile_assign()

for(var/obj/tile/O in world)
if(!choices.len)
return

var/pick_tile = pick(choices) //pick the tile icon state
O.picked = pick_tile //assign it
choices.Remove(pick_tile) //remove it from the list


I tried reading Lummox's tutorial on Associative lists. But to be honest, the way he writes code hurts my eyes.



Best response
I don't know what you're trying to do, but I'm just gonna guess it's like this. You want to go through the list and assign each tile a color the number of times listed. Soooo

for(var/obj/Tile/O)
while(choices.len)
var/color = pick(choices)
// I think it's called hashing, where you use strings to index lists
O.icon_state = choices[color] // choices["blue"] = 4
choices[color] --
if(choices[color] == 0)
choices.Remove(color)
Yeah sorry about that my explanations are terrible. I had to modify it abit, using while() for some reason wouldn't assign the colour to the tile.

You may be wondering why I use O.picked instead of icon_state. It's due to me wanting the player to not know what type of tile it is, until it's revealed.

Anyway here's how i modified it.

    proc
tile_assign()
for(var/obj/tile/O in world)
if(!choices2.len)
return

var/colour = pick(choices2)
O.picked = colour //choices2[colour]
choices2[colour]--

if(choices2[colour] == 0)
choices2.Remove(colour)


Thanks for the help. :)