ID:158295
 
Ok, so I'm trying to make something that will check all free spaces on a "bench" (slots to place things), and I can't seem to figure out what the hell I'm doing lol.

handler
proc
playeronebench()
var/obj/x = player1.GetClick()
if(istype(x,/obj/cancel))
return 1
if(istype(x,/obj/card/)&&x in player1.hand)
var/obj/free_spot //used to reference the free card slot.
for(var/obj/table/bench/b in table)
for(var/obj/card/c in b.loc) //for cards in the location it's currently looking
continue //If there's already a card on the spot, continue searching.
//Here is where if the loop ran completely through, and no free spots.
player1<<"\red You don't have any bench space!"
return 1

player1.hand -= x



Okay nevermind, it was as simple as this: EDIT: That actually doesn't work either >_>
        playeronebench()
for()
var/obj/x = player1.GetClick()
if(istype(x,/obj/cancel))
return 1
else if(istype(x,/obj/card/)&&x in player1.hand)
for(var/obj/table/bench/b in table)
var/obj/card/c
if(c in b) //if there's a card in that slot...
continue //keep looking
else //else if there's no card in the slot...
x.loc = b.loc
player1.hand -= x
player1.Updategrids()
break
else //something that you shouldn't click.
continue //repeat it all lol



Ok, and then I final figured it out- it was all in the process of elimination!
        playeronebench()
for()
var/obj/x = player1.GetClick()
if(istype(x,/obj/cancel))
world<<"u select cancel noob."
return 1
else if(istype(x,/obj/card/)&&x in player1.hand)
var/list/bench_pieces = new
for(var/obj/table/bench/b in table) //add all benches to the list
bench_pieces += b
for(var/obj/table/a in bench_pieces) //looking through bench pieces...
for(var/obj/card/c in a.loc) //find peices of the bench with a card already in it...
bench_pieces -= a //remove that from the list of available slots.
if(!bench_pieces.len) //no available slots!
player1<<"\red There is no room on the bench."
return 1
else //else, if there is available slots...
for(var/obj/table/t in bench_pieces) //pick one in the available
x.loc = t.loc
player1.hand -= x
player1.Updategrids()
break //break this and see if you want to place more cards :)
else //something that you shouldn't click.
continue //repeat it all lol
You should not need two procs (playeronebench() and playertwobench()) for this. They are performing the same operation, but on different data, so just pass the data (or something that can be used to find the data, IE the player number) as an argument to a single proc.
In response to Garthor
Good idea, except the data is slightly different because there's the object "bench", and then there's the object "bench1". So it's just easier to keep it seperate :)

EDIT: Although I can see how since I titled it "bench", and not "bench1" may have been confused. (it actually confuses me sometimess -.-)
In response to Speedro
Why would there be a "bench" and a "bench1" if they are, fundamentally, the same thing?
In response to Garthor
No, there's a "bench" and a "bench2", each belonging to the handler to sort where cards are located.