Problem description:
I've been working on a merchant system of buying/selling resources and the code length is getting too long. I know of a way to fix it, but I don't know if BYOND actually supports it.
I just want to store variables in a list and index the list rather than having to make a separate if statement for each resource just because I have to put in that resource's unique variables for price and quantity. Is this possible?
Thanks for your reply, Death.
var/b=input("Which resource do you want to buy?") in rlist The problem isn't much with the organization as it is with the variables. I have separate merchant "databases" that store the quantities of items and their price. The price goes up or down slightly depending on if people are buying or selling it. The issue is that all these different resources have a price variable and a quantity variable, and I've been putting them in for each resource, but I was wondering if its possible to put them in a list and get the variables that way. |
You really want some datums for this.
Basically, have a bunch of "Product" datums, each for the kind of product that needs selling/buying: Product Basically the datums store all pertinent data to a specific stock of a product, for a particular vendor, and controls it's own pricing. The vendor then just needs a list of these. |
I assume what you are doing at the minute is something like this?
An easier way to do this without the use of multiple if statements and lengthy code is;
-Show the user a list of things the merchant sells.
-Optionally, make this list include pricing (have the list contain [item.name] coupled with [price].)
-When the user picks an item from the list, do your input() statement asking if they'd like to buy it.
-Deduct the gold if so, otherwise return to the list or exit the merchant.
You'll want to use a for list proc followed by Input() to accomplish what your many, many if statements are doing.