ID:147768
 
I'm using a list to save anyone who was muted and logged out afterwards, but for whatever reason, the following code does NOT work.
        if(mute.Find(usr.key) || mute.Find(usr.client.address))
usr.mute = 1

It's initialised, saved as, treated as and appended to as a list, but the list.Find() proc will not work.

IU.dm:103:error:mute.Find:undefined proc
IU.dm:103:error:mute.Find:undefined proc
Enigmaster2002 wrote:
I'm using a list to save anyone who was muted and logged out afterwards, but for whatever reason, the following code does NOT work.
        if(mute.Find(usr.key) || mute.Find(usr.client.address))
usr.mute = 1
It's initialised, saved as, treated as and appended to as a list, but the list.Find() proc will not work.

IU.dm:103:error:mute.Find:undefined proc
IU.dm:103:error:mute.Find:undefined proc

Ah, but is it declared as a list? You should make sure that's var/list/mute, not just var/mute. There's where the error comes in.

Using : instead of . would get rid of the compiler error, but it's of course not as safe because what you see here is a helpful sanity check.

Lummox JR
In response to Lummox JR (#1)
It IS defined as a list variable, that's what annoys me.
<dm>
var/list
mute
In response to Enigmaster2002 (#2)
Well, I'd have to see more of your proc to figure this out. The problem lies beyond the very very small snippet you posted.

I did notice that usr appears in your snippet, even though the snippet itself doesn't look like it belongs in any kind of verb-like action. It looks like something that should be done passively at login.

Lummox JR
In response to Lummox JR (#3)
mob/other/choosing_character
Login()
if(mute.Find(usr.key) || mute.Find(usr.client.address))
usr.mute = 1
spawn()
src.ChooseCharacter()

var/list
mute

world
New()
..()
var/savefile/G = new ("mute.sav")
G["mute"] >> mute
if(isnull(mute))
mute = new /list
Del()
var/savefile/G = new ("mute.sav")
G["mute"] << mute
..()

I think that's about all of it.
In response to Enigmaster2002 (#4)
I'd just:

var/list/mute = list()

to begin with, and not screw with the isnull() stuff. Perhaps its having trouble trying to look in the list before it's been created at runtime. You may want to move ..() to the end of your New() proc and see what happens.
In response to Enigmaster2002 (#4)
Well, I see a few potential areas of concern; you're using weak programming practices in 3 spots and I think one of them is causing the trouble.

  • Login() is only somewhat usr-safe here. You don't need usr in Login() and src is safer anyway, so just use src.

  • You've named the mob var, mute, the same as a global var. This is a bad, bad idea. I'd at least rename the global list to something like mutelist.

  • You've used if(isnull(mute)) to check if the global list is a null. But to judge by what I've seen of others' attempts to save and reload lists, chances are an earlier version of your program screwed up the save and saved a string "" instead. If the string is empty, then you should be able to use if(!mute) instead. The latter I'd consider safer because it's a broader test. But safest of all in this particular case would be if(!istype(mute)), which will catch any non-list value including null. When putting in sanity-checking, always cast a wide net.

    Lummox JR