Author Topic: Add_action Question  (Read 2855 times)

Offline parham

  • Acquaintance
  • *
  • Posts: 30
    • View Profile
Add_action Question
« on: September 03, 2008, 09:16:46 AM »
Hi again!
Since I'm getting great answers to my questions, here is another one! I put this code in a room:
void init(){
    ::init();
add_action("test", "testing");
}
int test(){
call_out("say", 10, this_player()->getName() + " is testing!", this_player);
call_out("write", 10, "Testing successful!");
}

What I'm trying to test, along with whether I can make a simple command in a specific room or not, is whether the message can be given to a specific player or not, when it's different from what the rest of the people in the room see.
Thanks, and sorry for taking some forum space and precious time -- couldn't help it!

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Add_action Question
« Reply #1 on: September 03, 2008, 09:21:11 AM »
call_out() does not mix well with say() and write().

say() and write() generally expect there to be a "current command issuer",
and using call_out() interferes with that.

Get rid of the call_out()'s and it will likely work.

-Crat

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Add_action Question
« Reply #2 on: September 03, 2008, 09:55:48 AM »
By the way, the code you posted has an undefined
variable in it, and should not have worked as
you described on intermud. I prefer folks copy
and paste the actual code they have problems with.

This is an example of code that does what you
want without callouts:

Code: [Select]
void init(){
    ::init();     
    add_action("test", "testing");
}

int test(){
    say(this_player()->GetName() + " is testing!");
    write("Testing successful!");
    return 1;
}

Note that using code tags (the button with # on it)
makes code easier to read when you post it.

This is the code with callouts:

Code: [Select]
void init(){
    ::init();
    add_action("test", "testing");
}

int do_tell(object who){
    tell_player(who, "Testing successful!");
    tell_room(this_object(), who->GetName()+" is testing!", ({ who }) );
    return 1;
}

int test(){
    call_out("do_tell", 1, this_player());
    return 1;
}

-Crat

Offline wodan

  • BFF
  • ***
  • Posts: 434
  • Drink and code, you know you want to!
    • View Profile
Re: Add_action Question
« Reply #3 on: September 03, 2008, 04:39:15 PM »
call_out() does not mix well with say() and write().

say() and write() generally expect there to be a "current command issuer",
and using call_out() interferes with that.

Get rid of the call_out()'s and it will likely work.

-Crat
works better if you compile with this_player in call_out(), that's what it's for :)

Offline chaos

  • BFF
  • ***
  • Posts: 291
  • Job, school, social life, sleep. Pick 2.5.
    • View Profile
    • Lost Souls
Re: Add_action Question
« Reply #4 on: September 03, 2008, 05:00:23 PM »
Works even better if you eliminate as much usage of this_player(), say(), and write() as possible, forcing developers to stop using them as if they were magical "do what I mean" functions, with the predictable asininely broken results.

Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Re: Add_action Question
« Reply #5 on: September 04, 2008, 07:23:47 AM »
works better if you compile with this_player in call_out(), that's what it's for :)
There is a special this_player variable in callouts? That may be the answer to our "this code can't work" i3 discussion...
I think, therefore i may be wrong.
Please note that if you met a Raudhrskal in a place that's not related to muds, it wasn't me. *sigh*... back when I started there was zero hits on google for that name...

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Add_action Question
« Reply #6 on: September 04, 2008, 07:30:55 AM »
Quote
There is a special this_player variable in callouts?

I think Wodan means the compile time option THIS_PLAYER_IN_CALL_OUT.

It looks like by default it is indeed defined in the DS local_options, I
just avoid relying on it and don't remember testing it.

-Crat

EDIT:
In retrospect, I think you probably knew that and are asking if that
option adds a this_player variable. From my testing, it does not. The
code posted by parham failed with this_player as an undefined var
on a mud with THIS_PLAYER_IN_CALL_OUT defined.

« Last Edit: September 04, 2008, 07:34:49 AM by cratylus »

Offline wodan

  • BFF
  • ***
  • Posts: 434
  • Drink and code, you know you want to!
    • View Profile
Re: Add_action Question
« Reply #7 on: September 04, 2008, 07:38:00 AM »
That's the one!
It is entirely reliable, however in most libs this_player() isn't always what you think it should be when you get to the place where you do the call_out, but I don't think that risk would be all that big in i3 code. (it all goes wrong when one interactive ends up doing stuff because some other interactive did something)