ID:166896
 
Is there a way for me to check what the src.contents are when writing a "Sell" code, instead of putting 1000 if staements in the block? My "Buy" code seems to work ok, but the "Sell" code is a headache.

My code:
turf/counter
icon = 'turfs.dmi'
icon_state = "counter"
density = 1
Enter(mob/M)
switch(alert(M,"This is a weapon shop.", "How may I help you?","Buy","Sell","Cancel"))
if("Buy")
var/list/store1 = list("Clothes","Leather Armor","Leather Shield")
var/store = input(M, "Here are my wares","Armor") in store1
switch(store)
if("Clothes")
if(M.gold >= 20)
M.gold -= 20
new /obj/armors/clothes (M)
else
M << "sorry, you don't have enough gold"
if("Leather Armor")
if(M.gold >= 150)
M.gold -= 150
new /obj/armors/leather_armor (M)
else
M << "sorry, you don't have enough gold"
if("Leather Shield")
if(M.gold >= 90)
M.gold -= 90
new /obj/shields/leather_shield (M)
else
M << "sorry, you don't have enough gold"

----> if("Sell")
var/list/sell1 = list("[src.contents]")
var/store = input(M, "What are you selling?") in sell1
switch(store)
if("Clothes")
M << "I'll give you 10 gold pieces for that, Deal?"
var/list/yesno = list("Yes","No")
var/agree = input(M,"", "Well") in yesno
if("Yes")
M.gold += 10
del /obj/armors/clothes (M)
else
return 1


Suggestions and Comments welcome.
-pman-
var/obj/o=input("Sell what?") in null|usr.contents
if(!o) return
..
In response to Mysame
Thank you for that.

Now my new question is how do I reference the gold value of the contents?

code:
if("Sell")
var/obj/o=input("Sell what?") in null|M.contents
if(isnull(o))
M << "You have nothing to sell"
return 0
else
M.contents.Remove(o)
M << "You sold [o]"
return 1

I tried:
if("Sell")
var/obj/o=input("Sell what?") in null|M.contents
if(isnull(o))
M << "You have nothing to sell"
return 0
else
M.contents.Remove(o)
M << "You sold [o]"
M.gold += o.gold
return 1

code:
obj/armors
var/adef = 1
var/gold = 1
clothes
icon_state = "clothes"
adef = 10
gold = 20

Once again any and all help is appreciated.
-pman-
In response to PMan409
Perhaps you don't care, and if that's the case, please don't take this as an insult. I got to the bottom of a few posts by you, and at all of them I decided not to read the code you posted or try to help you fix your problems. I was about to close this third or fourth one, and it occurred to me that maybe you'd want to know why. The questions you ask aren't very good. They are generally simple ("how do I reference the gold value of the contents?") and are followed by relatively huge blocks of code.

This gives me an impression that, though I'm not sure it's accurate, reads as follows:
  • My code doesn't work quite the way I want it to
  • I don't want to spend time figuring out for myself how things work
  • I don't want to read demos, work through guides, or look at documentation in order to solve my problems
  • I do want to post my code and problems on the forums, and wait for people to fix those problems for me, because
    • It saves me work
    • It saves me effort
    • It saves me thought
    • It makes me happy
If that's not accurate, you need to change the way that you post in order to change the impression you give. I, for example, am almost guaranteed to give a response to a post that follows these general guidelines:
  • An interesting question is posted.
  • The poster has done at least a little research into what he's asking, and it shows.
  • The answer that the poster is looking for is either
    • specific, like "Is there a proc that does [whatever] that I just can't find in the reference?", or
    • non-demanding, like "Where do I look for resources if I want to be able to create a webforum application using DMCGI?" rather than "I need to know how to make a forum thx.".
  • The question is not so easy that I'm sure it's going to be answered by Mysame within the next 20 minutes


I wish you the best of luck posting in the future. If you want more information, or if you're bored anytime, you can check out this document. It contains a sort of primer on how to ask good questions to a technical forum or mailing list, and what to do before asking questions, or after getting answers that you don't like or don't understand, etc. Here's the link:

http://www.catb.org/~esr/faqs/smart-questions.html

Peace.