ID:1504895
 
(See the best response by FKI.)
Problem description: So I'm working on a tile checking mini-game and I ran into a few issues comparing tiles. So for example, if(A tile is the same as B tile), change both tiles to complete, assign points etc.

Obviously if it's wrong, return to default state.

Now there's an example below I just wrote up whilst actually writing this topic. I want some more experienced developers to let me know if this is a good way/bad way/totally wrong way and how I could possibly improve it.

Code:
var/list/example_list = list()


obj
proc
check_list()
for(var/obj/P in example_list)
if(P.picked == src.picked) //picked is a var from another proc for icon_state.
//do what needs to be done and then remove P from the list
return

tile
Click()
if(!clicked)
if(!example_list.len)
example_list.Add(src)
else
src.check_list()

Follow up, sorry for the bump.

So I mostly got the code to work with my game. I'm having one problem at the minute which is figuring out why the second clicked tile won't go to default state or win state.

Have a look.

var/list/click_list = list()

obj
proc/check_match(mob/M)
for(var/obj/tile/O in click_list)
if(O.picked == src.picked)
M.points++
M<<"Match!"
O.icon_state = "W" //W = correct
src.icon_state = "W"

else
M << "no match"
O.clicked = 0
src.clicked = 0
O.icon_state = "D"
src.icon_state = "D"
click_list.Remove(O)
var
clicked = 0
picked = ""

tile
icon = 'tile.dmi'
icon_state ="D" //d =default
Click()
if(!usr.started)
return
else if(!clicked)
if(!click_list.len)
click_list.Add(src)
else
src.check_match(usr)
src.icon_state = "[picked]"
src.clicked = 1
..()
Do you want the tile clicked to remain 1 even if you are giving them points for the match? Shouldn't it no longer be considered clicked?
Indeed I do, I was meant to put that above/below the click_list. I believe I may be using src incorrectly but I'm not entirely sure.

Only way I can figure out getting around the problem is using two lists since I'm unsure how to assign a variable multiple items in a list.

Updated version.
var/list/click_list = list()

obj
proc/check_match(mob/M)
var/I_state = ""
for(var/obj/tile/O in click_list)
if(O.picked == src.picked)
M.points++
M<<"Match!"
I_state = "W"
else
M << "no match"
I_state = "D"

O.icon_state = "[I_state]" //Did this instead of having icon_state four times.
src.icon_state = "[I_state]"
O.clicked = 0
src.clicked = 0
click_list.Remove(O)
var
clicked = 0
picked = ""

tile
icon = 'tile.dmi'
icon_state ="D" //d =default
Click()
if(!usr.started)
return
else if(!clicked)
if(!click_list.len)
click_list.Add(src)
else
src.check_match(usr)
src.icon_state = "[picked]"
src.clicked = 1
..()


Edit: Remembered I didn't want it to be clickable again once we got a match. That's why it was how it was.
You are trying to do something like this?
Yes, very similar to that FKI. Just as a note, I already have assigning the different tile types down.
In response to Rickoshay
Best response
So I went ahead and made my own version of what you have. I wrote this up quickly, but it compiles and does what it's supposed to (as far as I've tested). Let me know if there's any issues, anything you don't understand, etc.

mob
var/points = 0
var/started = 0
var/obj/tile/selected_tile = null

proc/select_tile(var/obj/tile/tile)
if(isnull(src.selected_tile))
tile.icon_state = "[tile.picked]"
src.selected_tile = tile
else
if(src.selected_tile.matches_tile(tile))
src.selected_tile.matched(tile)
src.scored()
else
src << "Wrong!"

tile.icon_state = tile.DEFAULT_STATE

src.selected_tile.icon_state = src.selected_tile.DEFAULT_STATE
src.selected_tile = null


proc/scored()
src << "You scored!"
src.points++
src.selected_tile = null //choose two new tiles from here.

obj/tile
var/picked = ""
var/const/DEFAULT_STATE = "D"
var/const/FLIPPED_STATE = "W"

Click()
if(!usr.started) return //hasn't started the game.
if(src.flipped()) return //already been flipped.

usr.select_tile(src)

proc/matches_tile(var/obj/tile/tile)
return src.picked == tile.picked

proc/matched(var/obj/tile/tile)
src.icon_state = src.FLIPPED_STATE
tile.icon_state = src.FLIPPED_STATE

proc/flipped()
return src.icon_state == src.FLIPPED_STATE
Took me some figuring out at first glance, but got it. Wasn't not sure how you were saving the first clicked tile till I looked at matches_tile(). Also no idea why i used a list for one piece of information, quite embarrassing since you just used a variable. (lol)

Thanks, really useful.
Just so you know there was an issue with being able to click the same tile twice. I just use if(clicked) return in Click and set back to zero once matched.

Edit: Oh wait, that wouldn't work.

Did this.

        Click()
if(!usr.started) return
if(src.flipped()) return
if(src == usr.selected_tile) return
usr.select_tile(src)