ID:1342718
 
Code:
obj/Equip/Weapon/Click()
if(src in usr.contents) return
if(usr, "Equipment", "is-visible=true") return
if(alert("Would you like to buy this [src] for [price] money!","Buy","Yes","No")=="No")return
if(src in usr.contents)
return
if(usr.Gold>=price)
var/obj/s=new src.type
usr.contents+=s
usr.Gold-=price
s.suffix=null
usr.client.statpanel="Inventory"
else
alert(usr,"You don't have enough Gold.")
return


Problem description:
ok basically, how its set up is, you equip it. and it shows up into a winset. the problem is. its trying to buy the weapon, that you have equipped.
so instead of DblClick() to unequip. i get a message asking if i wanna buy it....how do i make it so that if i Click() inside the winset it doesnt give me that message
ive tried both, but no matter which i try, when i click/dblclick on the window it asks me to buy it. i want to unequip when i click on it not act like its in a shop panel
    DblClick()
set src in oview(2)
usr<<"Look around!"
usr.shop=src.contents
usr.client.statpanel="Shop"


thats what calls the shop panel

obj/Equip/Weapon/Click()
if(src in usr.contents) return
//if(winset, "Equipment", "is-visible=true") return
if(alert("Would you like to buy this [src] for [price] money!","Buy","Yes","No")=="No")return
if(src in usr.contents)
return
if(usr.gold>=price)
var/obj/s=new src.type
usr.contents+=s
usr.gold-=price
s.suffix=null
usr.client.statpanel="Inventory"
else
alert(usr,"You don't have enough gold")
return


that is for buying the item

    DblClick()
var/mob/owner = usr
if(Slot in owner.Equipped_Items)
if(!(owner.Equipped_Items[Slot] == src))
usr << output(null, "[Slot]_Equip:1,1")
var/obj/Equip/item = owner.Equipped_Items[Slot]
owner.Equipped_Items[Slot] = null
owner.Equipped_Items -= Slot
owner.contents -= item
owner.contents += item
owner.str-=src.str_mod
On_Unequip(item)
owner.Equipped_Items += Slot
owner.Equipped_Items[Slot] += src
owner.str+=src.str_mod
On_Equip(src)
owner << output(src, "[Slot]_Equip:1,1")
else
usr << output(null, "[Slot]_Equip:1,1")
var/obj/Equip/item = owner.Equipped_Items[Slot]
owner.Equipped_Items[Slot] = null
owner.Equipped_Items -= Slot
owner.contents -= item
owner.contents += item
owner.str-=src.str_mod
On_Unequip(item)
else
owner.Equipped_Items += Slot
owner.Equipped_Items[Slot] += src
owner.str+=src.str_mod
On_Equip(src)
owner << output(src, "[Slot]_Equip:1,1")


thats the unequipping/equipping stuff. everything works fine...like i said basically the problem is, its trying to buy a "axe" anytime the "axe" is clicked on. when its not inside of my contents.
well i fixed the problem. thanks anyways
when i do change it to client, or mob. i get errors.


runtime error: Cannot read "Inventory".shop
proc name: Click (/obj/Equip/Weapon/Click)
usr: Cassidyx15 (/mob/Player/Dragonslayer)
src: Knuckles (/obj/Equip/Weapon/Knuckles)
call stack:
Knuckles (/obj/Equip/Weapon/Knuckles): Click("Inventory", "gamewindow.Status", "icon-x=24;icon-y=16;left=1")
There's nothing wrong with setting vars using usr inside of a DblClick(). Not sure why he uses it though since it's just a temp var, you could just use usr instead of owner.
Cause his owner var isn't used any where else and is temporary. There's no reason it should exist and it's weird it's there at all- chances are this is a borrowed snippet.
Cloud Magic wrote:
Why would you ever want to do such a thing in Click() though. If anything using Click() should call a proc the object owns that does the stuff he wants.

usr exists in the Click(), DblClick() and quite a few other functions, for this very reason, so using it is perfectly fine practice and makes perfect logical sense.

Having Click() call another proc just for the sake of not wanting to put it in Click() is stupid, although I guess that way you can rename it to something that makes slightly more sense for the sake of readability.