Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ General
➜ Why The value is old
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Tianxz
(30 posts) Bio
|
Date
| Fri 21 May 2010 05:29 PM (UTC) |
Message
| I have a trigger that get value $a from command hp.
In PHP, The code is
Function aaa()
{
$world->Excute('hp');//This command will get new value for $a
$world->DoAfterNote(2,$a);
}
But the result is The value of last time. It doesn't the value that had refreshed in 2s. I think The DoAfterNote only delay the display. But the content wasn't the result after 2s. Isn't it? Could you tell me which command can display real result.
| Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Fri 21 May 2010 07:39 PM (UTC) |
Message
| When this code is evaluated:
$world->DoAfterNote(2,$a);
The current value of $a is passed to DoAfterNote.
If you want the future value of $a to be used, you need to evaluate it again, for example by registering a function call with DoAfter rather than using DoAfterNote, such that the function call picks up the (then-current) value of $a. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #2 on Fri 21 May 2010 07:59 PM (UTC) |
Message
| $world->DoAfterSpecial(2, "$world->Note($a)", 12)
This will take the text in the middle and run it as script (that's what the 12 is for) after 2 seconds. Since the string isn't evaluated until 2 seconds later, you get the value of $a at that point in time. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #3 on Fri 21 May 2010 08:06 PM (UTC) Amended on Fri 21 May 2010 08:07 PM (UTC) by David Haley
|
Message
| Ah, no, PHP will evaluate $a as-is.
You need to use single-quotes to have it not evaluate $a.
$ cat test.php
<?
$a = 5;
print("Hello $a\n");
print('Goodbye $a' . "\n");
?>
$ php test.php
Hello 5
Goodbye $a
$
|
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #4 on Fri 21 May 2010 09:34 PM (UTC) |
Message
| Whoops, I forgot about that! Thanks DH.
$world->DoAfterSpecial(2, '$world->Note($a)', 12) |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #5 on Sat 22 May 2010 12:23 AM (UTC) |
Message
| It's kind of annoying when you have special behavior due to which quotation mark like that, especially when you come from lots of Lua and Python where ' and " mean the same thing. :P FWIW I often forget it too, and I tend to use single quotes and my variables never get subbed in when I write Perl or PHP... (although I write almost no PHP these days) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nick Gammon
Australia (23,052 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sat 22 May 2010 01:00 AM (UTC) |
Message
| Personally I'm not that keen on languages that inline variables like that. For example, if you want to send "the contents of variable 'a' followed by 'a'" then this won't work:
... because that is the contents of variable 'aa'.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #7 on Sat 22 May 2010 01:30 AM (UTC) |
Message
| Does PHP have anything spiffy to get around that like the following in Perl?
|
It is much easier to fight for one's ideals than to live up to them. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
22,630 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top