ID:142776
 
Code:
mob
verb/Give(mob/M in oview(1))
switch(input("What would you like to give [M]?")in list ("Gold","Items","Nevermind"))
if("Gold")
var/G = input("How much gold would you like to give [M]?",1,usr.gold)
switch(input("Are you sure you want to give [G] gold to [M]?")in list ("Yes","No"))
if("Yes")
M.gold += G
usr.gold -= G
M << "[usr] gives you [G] gold."
else
return

if("Item")
var/obj/I = input("What item would you like to give to [M]?",usr.contents)
switch(input("Are you sure you want to give this to [M]?")in list ("Yes","No"))
if("Yes")
M.contents += I
M << "[usr] gives you a [I]."
else
return
else
return


Problem description:

It would be very helpful since I have been thinking of another way how to do this for about 2 weeks. This code doesn't rise any errors, it just doesn't work while running the game. Just to tell you this game is a Live! game and I have tested Giving items to other players. It doesn't work.
The reason this isn't working, is because you aren't properly using the input() function. The input function works like this:

input([user,]text[,title,default]) [as specifier] [in container]

text: the only required field will display a message in the window.

optional arguments:
user: will display the message to a specific user. This defaults to usr. Usr is generally the client/mob that made an action last.

title: the title of the popup window.

default: what value will be highlighted when the window is created.


Specifier:

The specifier can be multiple things, a generic type (obj, mob, turf, area, etc.), or a type of data (text, num, anything, or null)

If you use anything, it must always come after every other specifier.
If you use null, you will have a cancel button in the window.

Multiple specifiers can be combined by using a binary or (|) between each specifier.


Container:

This is specifically for selecting things out of lists. Do not use the 'in' keyword if you are wanting a string entry, or a number entry.

Second, didn't include any error handling. If you gave someone an item, and then didn't click "yes", and then you successfully gave the same item to another player, you could swindle the item out of one player's inventory into another's. I just added a simple trap to keep that from happening.

mob
if("Item")
var/obj/I = input("What item would you like to give to [M]?") as null|anything in usr.contents
if(!I)
return 0
switch(input("Are you sure you want to give /a [I] to [M]?")in list ("Yes","No"))
if("Yes"&&usr.contents.Find(I))
M.contents += I
M << "[usr] gives you /a [I]."
else
return
else
return
In response to Ter13
Thought it would work, but there is one problem. There is only one line that gets an error this one:
if("Yes"&&usr.contents.Find(I))
In response to Oasiscircle
That's because you can't do that in a switch statement. You need to change it to this:

if("Yes")
//because there was a delay for input, they might've dropped the item
if(I.loc == usr)
//give the item
else
//don't give the item
In response to Garthor
Yay, no errors. Just one thing... I still can't Give anything! It doesn't even move from your contents... need help...
In response to Oasiscircle
Oasis I found the problem lol, call me and ill tell you what you did wrong o.O
In response to Nategrant
I know figured it out too. I didn't add the 's'.