Author Topic: genetics.c - RemoveBlindness() and eventBlind() observations  (Read 599 times)

Offline Lash

  • Acquaintance
  • *
  • Posts: 42
    • View Profile
genetics.c - RemoveBlindness() and eventBlind() observations
« on: March 16, 2016, 10:03:14 AM »
The functions static void RemoveBlindnes() and varargs mixed eventBlind() were not behaving as I expected. A test character was blinded by an npc, however when I tried the RemoveBlindness function as an admin on the test character I received the following output:

Code: [Select]
call test->RemoveBlindness()
The function RemoveBlindness() is not in OBJ(test /secure/save/players/t/test)

Removing the static type (void RemoveBlindness() instead of static void RemoveBlindness()) resulted in the following output when the mud was restarted and the character was blinded:
Code: [Select]
call test->RemoveBlindness()
OBJ(test /secure/save/players/t/test) -> RemoveBlindness() = 0

The character had vision restored. If the character was NOT blinded and the admin used the call test->RemoveBlindness() call the following output was received:

Code: [Select]
*Tried to take a member of something that isn't a class.
Object: /secure/save/players/t/test (/lib/genetics.c) at line 53

'<fake>' at /secure/save/creators/l/lash (/<driver>) at line 0
'cmdAll' at /secure/save/creators/l/lash (/lib/command.c) at line 231
'cmd' at /secure/cmds/creators/call at line 37
'CATCH' at /secure/cmds/creators/call at line 37
'<fake>' at /secure/cmds/creators/call (/<driver>) at line 0
'RemoveBlindness' at /secure/save/players/t/test (/lib/genetics.c) at line 53
Trace written to /log/catch
OBJ(test /secure/save/players/t/test) -> RemoveBlindness()
Error in execution: *Tried to take a member of something that isn't a class.

Well, that makes sense - the character is not blinded so the class object is not present. The RemoveBlindness function is now
working as expected (I think).

In eventBlind() the messages weren't being returned correctly. Here's the code (called from an npc) that was used to blind the character:
Code: [Select]
void blindness(object ob){

    object target = ob->GetCurrentEnemy();
    object env = environment(ob);
    int save = target->GetMagicResistance();
    int s_throw = random(99)+1;

    if(target->GetBlind()){
    return;
    }
    if (s_throw <= save){
        tell_room(env, "\n"+capitalize(target->GetShort())+" resists "+ob->GetKeyName()+"'s magic attack!\n", ({ ob, target }));
        tell_object(target, "\n%^BOLD%^%^YELLOW%^You resist being blinded by "+ob->GetKeyName()+"!%^RESET%^\n");
        target->eventTrainSkill("magic defense",save,s_throw,1);
        return;
    }
    else{
    target->eventBlind(target, 100, ({"\n%^BOLD%^%^GREEN%^You have been blinded!%^RESET%^\n","\n%^BOLD%^%^YELLOW%^You can see again!%^RESET%^\n"}) );
    tell_room(env, "\n"+capitalize(target->GetShort())+" seems to be blinded!\n", ({ob, target}));
    }
}

Looking at varargs mixed eventBlind() and comparing it to the RemoveBlindness function, it seemed like something was amiss so I did this:
Code: [Select]
varargs mixed eventBlind(object who, int amt, mixed end){
    Blind = new(class blindness);
    Blind->count = amt;
    Blind->end = end;
   /*following code added as seen in RemoveBlindness() function*/
    if( arrayp(end) ){
        send_messages(end[1], end[0], this_object());
        tell_player(who, "end[0] is "+end[0]+"and end[1] is "+end[1]);
    }
    else if( functionp(end) && !(functionp(end) & FP_OWNER_DESTED) ){
        evaluate(end, this_object());
    }
    else{
    tell_player(who,"You have been blinded!");
    }
    /*end addition*/
    return 1;
}

The messages are being returned correctly as seen by the output:
Code: [Select]
You have been blinded!

end[0] is
You have been blinded!
and end[1] is
You can see again!

After the 100 tick timer counts down (coded in the npc eventBlind() function) the characters vision is restored and the correct "You can see again!" message is displayed.

But hold on!

Why does this from eventBlind()
Code: [Select]
send_messages(end[1], end[0], this_object());

result in the correct order of the messages displayed? I would have thought the 2nd element of the array end[1] would have been
displayed first! Instead, it seems like it's backwards! But it works as expected...

Also, if I use this command as an admin:
Code: [Select]
call test->eventBlind("secure/save/players/t/test",10,({"you are blind","you can now see"}))

the test character is blinded for 10 ticks and the correct messaging is displayed.

Anyway, just some observations I noticed that I thought I would share. If anyone has more insight to this, or made other changes,
your input would be aprreciated.
« Last Edit: March 16, 2016, 10:05:42 AM by Lash »

Offline Lash

  • Acquaintance
  • *
  • Posts: 42
    • View Profile
Re: genetics.c - RemoveBlindness() and eventBlind() observations
« Reply #1 on: March 16, 2016, 11:15:45 AM »
I really need to sit on posts for a day or two...

Clarifications: When I wrote:

In eventBlind() the messages weren't being returned correctly.

The output I was receiving after my character was blinded by the function called in the npc consisted of only the second string in the messaging array. So when blinded I got the "You can see again!" message, and when the blindness wore off I got the "You can see again!" message.

When I wrote "...it seems like it's backwards! But it works as expected..."

I meant  "It works like I want it to work", meaning the message "You have been blinded!" was returned when the character was blinded by the npc, and "You can see again!" was returned when the blindness effect wore off.