ID:142408
 
I have been trying to make a store where you can purchase items but i just can't quite get it.
Here is a code that I screwed up on:

mob
verb
Buy(store in oview(1))
var/form = input("Which of these would you like to buy? Bomb-$30,Bones-$15", "Store") as null
if(form-"bomb")
usr.wealth-=30
usr.inventory+= bomb

I defined everything but it just wont work.
This code is probably way off but I need help.
Any help?
Conno1234 wrote:
This code is probably way off but I need help.

Yes, in fact 95% of the whole code is way off.
You need to learn before you attempt to make a game. You can't just guess it as you go, as you see that doesn't work.
In response to Kaioken
ok, thanks
You have the right idea, but your code is, well, bad. For starters, you can't use input() like that. If you want to present a list of available items, you want to do this:

var/form = input("Which of these would you like to buy?", \
"Shopkeeper") as anything in itemList


Where itemList is a list of available items.

Also, you can't check what <code>form</code> is like that:

if(form-"bomb")


What you want to do is use the == operator.

if(input == "bomb")


You're slightly off with how you're trying to locate stores as well. You need to define the type of object a store is, and then locate it like this: (store/someStore in oview(1)), where <code>store</code> is the type and <code>someStore</code> is a reference.
In response to DivineO'peanut
Ok but how would the part after the thing below go?
if(input =="bomb")
I don't know if that part is right.
Would it have anything to do with the code below?
usr.inventory+="bomb"
I can understand the input() part but the inventory piece is fuzzy
Can you explain?
In response to Conno1234
In response to Conno1234
If <code>usr.inventory</code> is a list, then your code should work. However, if your intentions were to append an object to the list, you'd do something like this:

if(input == "bomb")
usr.inventory += /obj/someObj
// replace /obj/someObj with the object you want to append


Also, I know it's some cheesy advice, but I recommend reading (or re-reading) the first chapters of the DM Guide- this stuff should be covered there.
In response to DivineO'peanut
DivineO'peanut wrote:
usr.inventory += /obj/someObj
// replace /obj/someObj with the object you want to append

That would probably need to be new /obj/someObj, if already. But I doubt there's much use of trying to help unless you're going to teach him DM, judging from his first post.
In response to Kaioken
Whoops, good catch! In my defense, I haven't slept for over 40 hours, so cut me some slack. :P
In response to DivineO'peanut
it said that input was an undefined variable