Using $world->doafter in if()

Posted by Nid on Tue 29 Aug 2006 05:12 PM — 3 posts, 16,375 views.

Sweden #0
Hey again, newbie speaking.

I'm trying to do this:

sub testing
{
if ($world->getvariable("test") =~ 1)
{
$world->doafter(10, $world->setvariable("testing", "1") );
$world->note($world->getvariable("testing"));
}
}


The problem here is that it sets the variable testing to 1 immediately, it doesn't wait 10 seconds. hence, the $world->note will show "1" instead of 0.

Any way to correct this?

Thanks in advance.
Australia Forum Administrator #1
You have a couple of problems here. For one thing, DoAfter is supposed to have a string as its second argument, eg.



$world->DoAfter(10, "eat fish" )


You haven't quoted the argument, so it will be done immediately.

The second problem is that even if you do that, it will send the script command to the MUD: eg.


$world->DoAfter(10, '$world->SetVariable("testing", "1")' );


This at least quotes the command, but it will send '$world->SetVariable("testing", "1")' to the MUD after 10 seconds. So what you want is DoAfterSpecial, and send to the script engine, like this:


$world->DoAfterSpecial(10, '$world->SetVariable("testing", "1")' , 12);

Sweden #2
Worked perfectly, thanks Nick!