[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Why The value is old
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Why The value is old

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Tianxz   (30 posts)  [Biography] 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.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] 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
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] 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
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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:


$aa


... because that is the contents of variable 'aa'.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] 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?
 ${a}a 

It is much easier to fight for one's ideals than to live up to them.
[Go to top] 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.


5,083 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]