ID:628927
 
(See the best response by DarkCampainger.)
When I activate this verb via a button on the shop window, a dialog pops up to select an object in the usr.contents before the alert comes up. I don't know why there is a prompt to select an object in usr.contents. The purchased item will always go to the user's equipped pack (usr.pack).

obj/object/verb
PurchaseSelected()
if(usr.SelectedObject)
var/obj/object/L = usr.SelectedObject
if(!(L in usr.pack))
if(L.price1)
if(alert("Would you like to buy the [L.name] for [L.price1] copper?","Buy","Yes","No")=="No")return
usr.copper-=L.price1
var/obj/object/s=new L.type
s.loc=usr.pack
usr.IncreaseWeight(O=s,P=usr.pack)
usr.WeightLabel()
usr.UpdateShop()


Thanks for any assistance.
I'm not quite sure why that is happening, but that's probably because i don't understand what the code is doing enough. If you could, post up what SelectedObject variable is/does, as well as price1 variable. I might be able to assist you more then hopefully.
Best response
When you execute a verb without specifying a source (src) object, Dream Seeker will display an input for selecting which object the user meant to execute the verb from. I think this is what you're seeing.

/obj verbs default to a src setting of set src in usr. So, you can use the set src=usr verb setting instead to have DS automatically pick an object to run PurchaseSelected() on. However, I doubt that's what you want.

You can also embed the desired source in the button's command itself by passing the name of the source as the first argument, but that seems messy as you'll have to keep updating the buttons with the item names.

What might be the best solution is to write a verb on the mob for purchasing items, and have your button call that (while passing an index to the item in the "store" list so you can determine which one they selected).

Of course, this is all guess-work as you didn't really describe your shop interface. So if none of these options are suitable, let me know and I'm sure we can come up with some more :)


I need to stop trying to answer questions at 5:00AM. If SelectedObject holds the object the user wants to buy, then this verb should be under your mob type instead of your obj
In response to DarkCampainger (#2)
DarkCampainger wrote:
I need to stop trying to answer questions at 5:00AM. If SelectedObject holds the object the user wants to buy, then this verb should be under your mob type instead of your obj

Eureka. Thanks again!