ID:2153033
 

Alright, so I'm trying to work with a list for a store in my game... I can
sell things to the store, but when I try to buy, the code fails and says can't read ""Ruby.Value""... I thought that this was because in my list "Ruby" is only the name of the object, and DM doesn't know what Ruby means or where it is defined. My code looks like this:
Code:

var/list/shop = list("Ruby")as obj


Now, I thought in order to explain where the Ruby is, I'd do it like this:

var/list/shop = list("Ruby",Ruby) as obj


But this comes up as an error because DM thinks Ruby is an undefined variable. so to beat this I figured I'd define the Ruby by its root.

var/list/shop = list("Ruby",/obj/Ruby) as obj

This compiled properly, but doesn't actually define the root, just puts the root in the list of things I can buy...
My main priority is telling DM what I am trying to buy so DM can read obj.Value and sell it to me.
I believe this is an easy problem, and it is do to the fact I don't understand how to call or execute a list properly.

If someone can help me out with this I'd really appreciate it.



var list/shop = list(new /obj/Ruby)
// or
var list/shop = newlist(/obj/Ruby)

By default, input() in list shows the names of objects in the list.
Also you could use associative lists:

verb/Buy()
var/list/items = new
var/obj/O
for(O in selling) // this is a newlist() of items
items["[O.name]: $[O.price]"] = O
var/which = input("What would you like to buy?", "Buy") as null|anything in items
if(!which) return
O = items[which]
if(O.price > usr.gold)
usr << "You can't afford \a [O] right now."
return
// get a type path so we can create a copy
which = O.type
O = new which(usr)
usr.gold -= O.price
usr << "Thank you! Enjoy your [O]."