List problem in Developer Help
|
|
I can not seem to get this code to work correctly. Background: Every intercom has a different sname like "outside intercom". I get bad index errors
Send_To(msg as text) set src in view(1) var list globalintercom intercomchooser for(var/obj/electronics/messagenet/reciever in world) globalintercom[reciever.sname] = reciever intercomchooser += reciever.sname var/chose = input("Which intercom would you like to broadcast to?","Intercom Chooser") in intercomchooser + "nothing" var/obj/reciever = globalintercom[chose] if(reciever) view(reciever) << "[usr]:MessageNet:[sname] sends, [msg]"
|
|
The problem may be that you're using two different lists when you only need one. You set up the globalintercom list as an associative list, but then you're also using a second list of names (intercomchooser) that's not associative; that's the one you're passing to input().
Your problem may be fixed by eliminating the redundant intercomchooser list, and changing all the other references to globalintercom:
The other thing I'd watch out for: Make sure sname isn't a number. If it's a number, list association won't work the way you expect it to, and that will definitely give you a bad index. If sname is a number, then change the list to go by "[receiver.sname]" instead of receiver.sname directly.
Lummox JR