ID:268621
 
Well, as it happens I had been doing my market system completely wrong according to lummox, and now I am trying to go back and fix it.

So lets start with what I got -

var/list/ITEM_DATA=list("food cost"=10,"Stone cost"=10,"Rock cost"=20)
var/list/items=list("food","Stone","Rock")
mob/verb/Market()
var/t=input("What would you like to buy today?") as null|anything in items
if(isnull(t)) return
if(!client) return
var/et=input("How many you want to buy") as null|num
if(t=="food")
if(src.money>=ITEM_DATA["[t] cost"])
src.money-=ITEM_DATA["[t] cost"]
src.fd+=et
else
//do the rest.. with having to input each individual variable


the problem with this is I have to do an if check for every single item because I keep my variable names short and sweet for easy typing and my game is a strategy game so I don't know why but variables for each resource seem necessary unless I bother making 20 different types of resources into objects and such and completely changing all the systems that I have in place... this could be a real pain. Well I could just make one object and change the icon_state, name etc at creation to avoid types... but I've got about 10-20 procedures that are fine and dandy with no problems and using objects would mean having to completely redo them... hmm well any opinions are appreciated. If only vars[] worked like how I thought it did this wouldn't be a problem :P


Hopefully I don't end up having to go with the long approach and doing if statements... But I'd rather do that then change all the procedures I currently have :P
So far you're still thinking in terms of your old vars[] system. The ITEM_DATA list is in fact completely redundant. Not only was it unnecessary to use different strings ("food cost" vs. "food") from those in your items list, but you could have put the price info just as easily into the items list. The only reason you might need a second list is to store types.

Lummox JR
In response to Lummox JR
ahhh of course I knew that I just wasn't thinking at the time I whipped up that example...

The problem is that with vars[] I could directly call a variable of src (or atleast I thought I could) thus saving having to if() checks to see what item was picked and thus edit that variable...


if(t=="food") src.food+=te

vs

src.vars[t]+=te

:P

so I guess my question is how would I make it simple and easy to edit like the 2nd one? Is there a way to do this with lists?

I mean it's not a BIG deal it won't take super long to go through and redo this after I thought about it, but it's still time best spent elsewhere... I just am drawing a blank on this one :P