ID:999287
 
Bare with me, the code is long but relevant.

proc
IM_Proc(mob/a,mob/b)
new/IM_Datum(a,b)


var
list
IMs = list()


mob
verb
privsay(msg as text)
var/IM_Datum/I = Find_IM()
if(!I) return
I.Message(src,msg)
closeim()
var/IM_Datum/I = Find_IM()
if(!I) return
I.Close_Window(src)
ignoreim()
var/IM_Datum/I = Find_IM()
if(!I) return
I.Exit_Chat(src)
proc
Find_IM()
var/IM_Datum/I
for(var/IM_Datum/i in IMs)
if(winget(src,"[i][i.ID].chatinput","focus=true"))
winset(src,"[i][i.ID].chatinput","background-color=60,60,60")
I = i
return I
var/IM_ID = 0
IM_Datum
var
ID
mob/a
mob/b


New(mob/m1,mob/m2)
for(var/IM_Datum/I in IMs)
if((I.a == m1 && I.b == m2) || (I.a == m2 && I.b == m1))
problemarising
world << "chat window already made for this conversation"
return
a = m1
b = m2
IMs += src
IM_ID ++
ID = IM_ID
world << "[ID]"
winclone(a,"chat","[src][ID]")
winshow(a,"[src][ID]",1)
winset(a,"[src][ID]","title=\"[a.key] - [b.key]")

proc
Generate_Window(mob/m)
if(!winexists(m,"[src][ID]"))
winclone(m,"chat","[src][ID]")
winshow(m,"[src][ID]",1)
winset(m,"[src][ID]","title=\"[a.key] - [b.key]")
else
winshow(m,"[src][ID]",1)

Message(user,msg)
Generate_Window(a)
Generate_Window(b)
a << output("[user]: [msg]","[src][ID].chatoutput")
b << output("[user]: [msg]","[src][ID].chatoutput")

Close_Window(mob/m)
if(m == a)
a = null
if(m == b)
b = null
if(!a && !b)
del src


Exit_Chat(mob/m)
if(m == a)
b << output("[a] has left the chat","[src][ID].chatoutput")
a = null
else
b = null
a << output("[b] has left the chat","[src][ID].chatoutput")

Close_Window()



Del()
if(a && a.client)
winset(a,"[src][ID]","parent=none")
if(b && b.client)
winset(b,"[src][ID]","parent=none")
IMs -= src

mob
Logout()
..()
if(client)
ignoreim()


Problem description:

I am trying to have it so a player can have more than one popup window to talk to multiple people at the same time. The problem I'm running into right now is, when I try to talk to more than one person, the first popup window only sends messages to the last popup window I created. It's quite confusing and I've tried using a global variable to differentiate between winclones. Can anyone spot the issue? This is a long one, so kudos to anyone who takes the time.

Ever thought of using \ref?
How can I give a \ref to the datum? What's wrong with just using a global var to make a new ID for each new IM_Datum that is created? I think the issue is stemming from how I am figuring out which window belongs to which conversation with winclone. Right now I just check which window has focus and then see what the window's ID is called and match it to the datum, but it doesn't seem to work.

If I open one window to one person, it works fine. If I try to open another window to talk to another player at the same time, it works but if i try to use the first window (originally used to talk to the first player), it sends the message to the latest window created as well.