ID:141215
 


I got the above done by making 10 grids (card size) and then adding my mobs objects to them, my mob has the following var...

obj/cards/Monster1
obj/cards/Monster2
obj/cards/Monster3
obj/cards/Monster4
obj/cards/Monster5
obj/cards/ST1
obj/cards/ST2
... etc


Whats going to happen eventually is that my opponents cards will be in those slots, not my own mobs. But this is the best way to test it out without me needing another player.

Unfortunatly, in my recent updates the cards (objects) will now be facing in various directions, but i want them to be either as above, or sideways (Defense Position). When simply adding the usrs obj/cards/Monster1 to the grid, it follows whatever icon that card has (which is good for some things) but not when my opponents card objects can now face various directions (see http://www.youtube.com/watch?v=KAvv7PHqhvQ).

    if(usr.Monster3)

var/obj/cards/O = new Monster3.type
if(Monster3.FaceDown)
O.icon = 'card_back.dmi'
O.icon_state = pick("1","2","3","4")
O.icon = turn(O.icon,90)
else
var/icon/i = icon(initial(Monster3.icon),initial(Monster3.icon_state))
if(Monster3.Mode == "Defense") i.Turn(90)
O.icon = i

usr << output(O, "dwheel.m3")

else usr << output(null, "dwheel.m3")


The above code works. New problem now, it seems that once the object is added its being deleted? I want a click on the object in the grid to be treated like a click on the card itself (so my players can click the cards and see the card description). Currently clicking it does nothing, i tried to add some code to link it ~ but it didnt work at all.

When i tried to look at the objects variables to see if it was being set properly i got a runtime saying the object didnt exist, so its being deleted? but why? I assume its the garbage collector?
On creating, give "O" a tag (tag="lol" or anything). Worked for my garbage collecting errors.

Alternatively, you could be assigning an improper value to the variable.
In response to Mysame
Mysame wrote:
On creating, give "O" a tag (tag="lol" or anything). Worked for my garbage collecting errors.
You can also add it to a list (or place it on the map) and it will prevent garbage collection.
In response to AJX
Thanks. I tried the tag method, seems to work..

    if(usr.Monster3)

var/obj/cards/dgrid/O = new/obj/cards/dgrid(usr)

O.Owner = Monster3.Owner
O.name = Monster3.name
O.parent = Monster3
O.tag = "[usr.key]monster1"

if(Monster3.FaceDown)
O.icon = 'card_back.dmi'
O.icon_state = pick("1","2","3","4")
O.icon = turn(O.icon,90)
else
var/icon/i = icon(initial(Monster3.icon),initial(Monster3.icon_state))
if(Monster3.Mode == "Defense") i.Turn(90)
O.icon = i

usr << output(O, "dwheel.m3")
else
for(var/obj/cards/dgrid/D in usr.contents) if(D.tag == "[usr.key]monster1")
world << "[usr.key]monster1 found"
del(D)


Just need a for() to remove it after though. But yeah it all works as expected now. Thats a good point about perhaps adding it to a list, adding it to the map isnt an option though.
In response to UnknownDuelist
Instead of that loop you can do:


var/obj/cards/dgrid/D = locate("[usr.key]monster1") in world

In response to Nadrew
Oh ok thanks, ill try that. What would be better? Doing that or the loop? (from a resource POV?). I notice its making a new obj, then i delete that right?
In response to UnknownDuelist
It's not making a new object, it's creating a variable reference to an existing object. Using that reference you can actually alter the object any way possible. locate() is basically using its 'tag argument' system to find the object with that tag.
In response to Nadrew
My mistake, i didnt know about tag till today XD
In response to UnknownDuelist
UnknownDuelist wrote:
My mistake, i didnt know about tag till today XD
From personal experience the locate() functions faster than a loop, my assumption for why is because it is handled internally.