ID:271351
 
hi, im trying to make it so you can buy x amount of the same item like
var/amount = input("what you want","") as num
cost = amount*cost

or something like that, the problem is creating multiple objs, i dont kno how to create a bunch of objs, instead of one.
You can use a for loop:
for(var/i = amount, i > 0, i--)
new /whateveryoubought(you)


"you" would be whatever the person buying things is in this case, and "/whateveryoubought" is the type path of the thing being purchased.
Hope this helps. It's self-explanatory.
Note: the while(X) proc will repeat everythign under it as long as X is true (not "0" or "null")
mob/NPC/verb
Buy()
set src in oview(1)
var/ammount
var/price
var/item = input("Hello there! Interested in buying table complements?","Shopkeeper") in list("Fork","Spoon","Knife","Nevermind...")
switch(item)
if("Fork")
ammount = input("How many?","5 coins") as num
price = ammount*5
if(usr.Money < price)
alert(usr,"You can't afford THAT!")
return
if("Spoon")
ammount = input("How many?","3 coins") as num
price = ammount*3
if(usr.Money < price)
alert(usr,"You can't afford THAT!")
return
if("Knife")
ammount = input("How many?","7 coins") as num
price = ammount*7
if(usr.Money < price)
alert(usr,"You can't afford THAT!")
return
else
alert(usr,"See you later!","Shopkeeper")
return
usr.Money -= price
while(ammount)
ammount --
var/obj/X = text2path("/obj/Table/[item]")
new X(usr.contents)

Any questions ?
In response to Gooseheaded
@gooseheaded: heh heh, I read your post first and thought "that guy's code ought to work, why is he asking how to make multiple objects?". Lesson learned: read the posts in order.
In response to Gooseheaded

Comic Book Guy: "Most Helpful Code EVER!"

Thanks Goose!
In response to Gooseheaded
Why all the repeated code? Why while() instead of for()?

mob/shopkeeper
var/list/sold=list(/obj/fork, /obj/knife, /obj/spoon)

New()
for(var/k in sold) contents += new k
sold=null //Be green - preserve lists

verb/Buy()
set src in view(1)
var/obj/o = input("Which object would you like to buy?", "Shopkeeper") as null|obj in contents
if(!o) return //Allow cancel

var/n = input("How many would you like to buy?", "Shopkeeper", 1) as num
if(n<=0) return //More cancel
if(n!=round(n))
usr << "You must buy an integer quantity"
return

if(usr.money<o.price*n)
usr << "You don't have enough money"
return

usr.money -= o.price

for(var/i=1, i<=n, i++) new o.type(usr)


Untested, might not actually compile without minor syntactical changes (In particular, I don't think 'new o.type(usr)' compiles), but the changes that are required should be obvious.