var/obj/machinery/computer/shipcomms/connectedConsole
/obj/machinery/computer/shipcomms/attack_hand(mob/user)
var/obj/machinery/computer/shipcomms/sc
for(var/obj/O in stsc)
sc = O
if(sc.id != src.id)
dat += "<center><li>ID: [sc.id]"
dat += "<A HREF='?src=\ref[src];action=viewmessagelogs'>Message Logs</A> | "
dat += "<A HREF='?src=\ref[src];action=sendmessage;[src.connectedConsole = sc]'>Send Message</A></li></center><BR>"
Problem description:
Currently having a problem with this loop behaving odd.
the result of sc.id produces different results, but when I make connectedConsole a reference to sc, it's always the same object within the last iteration in the loop.
What is it I've done wrong? Thanks in advance.
Note: there is other code in the proc (such as var/datum/browser/popup) the reason I left it out is because it would make it easier to read. If it's requested I'll happily add the code onto the post.
Edit: To make things easier, here is the code of the entire class.
var/global/stsc[0]
/obj/machinery/computer/shipcomms
name = "STSC Console"
desc = "A console used for ship to ship communications (STSC)."
icon_screen = "comm"
icon_keyboard = "tech_key"
var
const
STATE_DEFAULT = 1
STATE_VIEWMESSAGELOGS = 2
STATE_SENDMESSAGE = 3
state = STATE_DEFAULT
id //must assigned in New() and not to be changed
messages[0]
obj/machinery/computer/shipcomms/connectedConsole
/obj/machinery/computer/shipcomms/New()
id = stsc.len+1
var/obj/machinery/computer/shipcomms/sc = src
stsc += sc
..()
/obj/machinery/computer/shipcomms/attack_hand(mob/user)
if(..())
return
user.set_machine(src)
var/dat = ""
var/datum/browser/popup = new(user, "shipcomms", "STSC Console", 400, 500)
popup.set_title_image(user.browse_rsc_icon(src.icon, src.icon_state))
switch(src.state)
if(STATE_DEFAULT)
dat += "<ul>"
for(var/obj/machinery/computer/shipcomms/sc in stsc)
if(sc.id != src.id)
dat += "<center><li>ID: [sc.id]"
dat += "<A HREF='?src=\ref[src];action=viewmessagelogs'>Message Logs</A> | "
dat += "<A HREF='?src=\ref[src];action=sendmessage;[src.connectedConsole = sc]'>Send Message message to [sc.id]</A></li></center><BR>"
dat += "</ul>"
if(STATE_VIEWMESSAGELOGS)
dat += "<A HREF='?src=\ref[src];action=default;'>Back</A><BR>"
for(var/datum/Message/M in messages)
if(M.receiver.id == connectedConsole.id & M.sender.id == src.id)
dat += "<center>[M.body]</center><BR>"
dat += "<center>+-----------------------------+</center><BR>"
if(M.receiver == src & M.sender == connectedConsole.id)
dat += "<center>[M.body]</center><BR>"
dat += "<center>+-----------------------------+</center><BR>"
if(STATE_SENDMESSAGE)
var/input = stripped_input(user, "Send a message to [connectedConsole.id].", "What?")
if(!input)
return
state = STATE_DEFAULT
var/datum/Message/M = new
M.body = input
M.sender = src
M.receiver = src.connectedConsole
src.connectedConsole.messages += M
messages += M
state = STATE_VIEWMESSAGELOGS
popup.set_content(dat)
popup.open()
/obj/machinery/computer/shipcomms/Topic(href, href_list)
if(..())
return
usr.set_machine(src)
if(!href_list["action"])
return
switch(href_list["action"])
if("default")
state = STATE_DEFAULT
if("viewmessagelogs")
state = STATE_VIEWMESSAGELOGS
if("sendmessage")
state = STATE_SENDMESSAGE
src.updateUsrDialog()
/obj/machinery/computer/shipcomms/Del()
stsc -= src
..()