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?
ID:142408
![]() Jun 8 2008, 6:49 am
|
|
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?", \ 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. |
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? |
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") 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. |
DivineO'peanut wrote:
usr.inventory += /obj/someObj 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. |
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.