ID:144850
 
Code:
Mail Code
            if("Mail A Letter: 5G")
if(M.gold >= 5)
var/list/letters=list()
for(var/obj/Inventory/Letter/L in M)
letters.Add(L)
letters.Add("Cancel")
var/obj/O=input(src,"Mail which letter?")in letters
if(O == "Cancel")
alert("Alright, if you change your mind, come back!","Talking to [src]")
return
var/list/mailboxes=list()
for(var/obj/Furniture/Mailbox/MB in world)
if(istype(M,/obj/Furniture/Mailbox)) mailboxes.Add(M)
mailboxes.Add(MB)
mailboxes.Add("Cancel")
var/obj/O2=input(src,"Mail the letter to which mailbox?")in letters
if(O2 == "Cancel")
alert("Alright, if you change your mind, come back!","Talking to [src]")
return
switch(input("Let me make sure: You want [O] sent to [O2]?","Talking to [src]", text) in list ("Corrent","Wrong"))
if("Wrong")
alert("Alright, lets start from the beginning..","Talking to [src]")
return
if("Correct")
if(M.gold >= 5)
M.gold -= 5
O2.contents += O
alert("Your mail was sent to [O2], thank you!","Talking to [src]")
return
else
alert("You don't have enough money to do that.","Talking to [src]")
return
alert("You don't have enough money to buy that.","Talking to [src]")
return


Problem description:
Bascilly players can go to the post office and buy a letter, fill it out, and then mail it through the post mob to any active mailbox objs in the game.

It compiles fine, but when I go to try it in game, I get a bunch of run time errors.

I didn't really study your code a lot but I do not believe you can define atoms with numbers, so that may be your problem. This isn't really a problem, but you have two checks to see if the mob has 5 or more gold.

-Exophus
What are the runtimes?

1.) Lists
a.) Don't use Add on just one item. Use +=, it's faster.
b.) Don't add a "Cancel" option to lists. It's just nasty. Limit your input() to as null|anything in letters, and then check for !input.
c.) Don't initialize lists until you need them. You don't appear to have a situation where this might go into effect here, but it's for future reference, since you initialize mailboxes and letters on sight. You then also check for !list.len every time you remove an item and set it to null each time, then the garbage collector will eventually pick it up.
2.) Instead of doing istype(M, /obj/Furniture/Mailbox), you can simply do istype( M ). This'll check it against the type it is.
3.) I don't know if this is in a proc or what, but you have usr abuse hidden in your alerts. I noticed you did remove the hidden usr in input, but you missed alert.
Ok ok I got it down a little bit further. It now works almost all the way to the end. What I did to test was first just try to mail a letter without a letter in my inventory. I get the correct messages.

Then I Bought a letter and tried to mail it, knowing full well there were no mailboxes in the world. Instead It just skips to the Cancel check under mailboxes.

mob/NPC/Monstro_Village_Post
name = "Monstro Village Post Office"
icon = 'Players.dmi'
icon_state = "shadow"
density = 1
New()
src.CreateName()
..()

verb/Talk()
set src in oview(2)
set category = null
var/mob/M = usr

switch(input("Welcome to the Village post office, what do you need today?","Talking to Post Master", text) in list ("Buy A Letter: 10G","Mail A Letter: 5G","Never Mind"))

if("Buy A Letter: 10G")
if(M.gold >= 10)
alert("Here is your letter, please come again!","Talking to Post Master")
M.contents += new/obj/Inventory/Letter
M.gold -= 10
return
alert("You don't have enough money to buy that.","Talking to Post Master")
return

if("Mail A Letter: 5G")

var/list/letters=list()
for(var/obj/Inventory/Letter/L in M.contents)
if(istype(L)) letters.Add(L)
letters += "Cancel"

if(letters.len<=1)
alert("You need a letter to mail first!","Talking to Post Master")
return

var/obj/L = input(M,"Mail which letter?")in letters

if("Cancel")
alert("Alright if you change your mind come back please!","Talking to Post Master")
return

var/list/mailboxes=list()
for(var/obj/Furniture/Mailbox/B in world)
if(istype(B)) mailboxes.Add(B)
mailboxes += "Cancel"

if(mailboxes.len<=1)
alert("There are no active mailboxes right now..","Talking to Post Master")
return

var/obj/B = input(M,"Send this letter to which mailbox?")in mailboxes

if("Cancel")
alert("Alright if you change your mind come back please!","Talking to Post Master")
return

switch(input("So you want to mail [L] to [B]?","Talking to Post Master", text) in list ("Correct","Wrong"))
if("Wrong")
alert("Ok lets start from the beginning then..","Talking to Post Master")
return

if("Correct")
if(M.gold >= 5)
L.loc = B.contents
M.gold -= 5
alert("Ok [L] was mailed to [B], please come again!","Talking to Post Master")
return
else
alert("You need more money before you can mail anything!","Talking to Post Master")
return