ID:161014
 
ok im trying to create an IM chat system and cant get it to work right. I think im going about it all wrong any help would be appreciated.

mob/verb
Whisper()
var/varPeople = list()
for(var/mob/T in world)
if(T.key)
varPeople += T
var/M=input("Who would you like to whisper to?","") in varPeople +list("Cancel")
if(M=="Cancel")
return
else
var/msg=input("") as text
M << output("\blue([usr.Village])\red([usr.rank])</FONT color>--[usr.name]: [html_encode(msg)]", "IMout.output")
M:sender=usr

mob
verb
send(msg as text)
if(usr.sender)
var/mob/M=usr.sender
M << output("\blue([usr.Village])\red([usr.rank])</FONT color>--[usr.name]: [html_encode(msg)]", "IMout.output")
M.sender=usr

the first code is to initiate the chat and the next is to send using the messager window. But i cant get the messager window to pop up
Set the IM window's "is-visible" parameter to "true".
In response to Kaiochao
ok i had it visible and i found my first mistake, but now the window is there when it starts and if they close the window it doesnt work. I dont want the window there at the start and also want it to appear when someone IMs someone
In response to Kaiochao
Kaiochao wrote:
Set the IM window's "is-visible" parameter to "true".

That or the winshow procedure.

//winshow(player, window, show=1)

winshow(M, "IMout")


But doesn't the return value get its type from the variable if it is not given with in the command? So is outputing to M correct?
You're doing everything wrong.

1. You should not loop through mobs, test if they have clients and add them to the list. The necessary way is to loop through clients then add their mobs to the list.

2. Adding "Cancel" is not good as well. You could make the input null.

3. To make the window pop up, use the winshow() proc.

4. There's no need for a Send() verb.

mob
verb
Whisper()
var/L = list()
for(var/client/c)
L[c.mob.name] = c
//associative list
var/client/C = L[input(src,"Who would you like to whisper to?","Whisper") as null|anything in L]
//lets you choose who to whisper
if(C)
var/msg = input(src,"Message:","Whisper") as text|null
if(!C)
alert("The recipient is no longer online.")
else if(msg)
C << output("\blue([src.Village])\red([src.rank])</FONT color>--[src.name]: [html_encode(msg)]", "IMout.output")
//sends the message to the mob
winshow(C, "IMout")
//shows the IM window
In response to Jemai1
thank you ill try that and i have the send verb there so once they start chatting with someone they dont have to keep selecting to keep whispering and just use the input on the chat window
In response to Jemai1
ok i got it to work now had to modify which windows i was outputting to. But now i would like to delete the test when the window is closed
In response to Jemai1
There's no need for an associative list. Use a simple regular one.