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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Variables not updating

Variables not updating

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


Posted by Kurapiira   (25 posts)  [Biography] bio
Date Thu 11 Mar 2010 11:13 AM (UTC)

Amended on Thu 11 Mar 2010 11:25 AM (UTC) by Kurapiira

Message
my hp prompt is catching the variables,
but when i go to display them, it shows the last value
of the variable...

i.e. HP: 208/208 Ftg: 61/61 MP: 22/22

( I cast a spell )

HP: 208/208 Ftg: 61/61 MP: 12/22

but the send function sends the first values..

any ideas?

trig value:
^HP\: (.*?)\/(.*?) Ftg\: (.*?)\/(.*?) MP\: (.*?)\/(.*?)$


script:
SetVariable ("hp","%1")
SetVariable ("maxhp","%2")
SetVariable ("ftg","%3")
SetVariable ("maxftg","%4")
SetVariable ("mana","%5")
SetVariable ("maxmana","%6")

Send ("'@hp @maxhp")
Send ("'@ftg @maxftg")
Send ("'@mana @maxmana")

should i be using setVariable for this?
p.s. the line I am capturing is hilighted in ansi from the mud...

Thanx for any help,
K.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #1 on Thu 11 Mar 2010 05:24 PM (UTC)

Amended on Thu 11 Mar 2010 05:25 PM (UTC) by Twisol

Message
Actually, the issue is a little more subtle. The @variable syntax isn't really part of Lua. Nick supports it by running your Send content through a preprocessor, which processes it before Lua does. It looks for the @variable and %1 things, looks up what their values are right at that moment, and then replaces them inline. So if you have this:

if "@variable" == "test" then

... then by the time Lua gets to it, it's actually (example):

if "test" == "test" then.

Got it? Now, what's going on is that it gets those values before you ever call SetVariable to change their values. You -are- changing the values, but it's not seeing that, because it already got the values beforehand. What you should do in this case is this:

SetVariable ("hp","%1")
SetVariable ("maxhp","%2")
SetVariable ("ftg","%3")
SetVariable ("maxftg","%4")
SetVariable ("mana","%5")
SetVariable ("maxmana","%6")

Send (string.format("'%s %s", GetVariable("hp"), GetVariable("maxhp")))
Send (string.format("'%s %s", GetVariable("ftg"), GetVariable("maxftg")))
Send (string.format("'%s %s", GetVariable("mana"), GetVariable("maxmana")))


I used string.format because it looks tidier than a bunch of concatenations. ;) And in case you were wondering, the %s things in the string.format call are not bothered by the preprocessor, since those are letters, not numbers.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,991 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Thu 11 Mar 2010 06:29 PM (UTC)
Message
Twisol said:

And in case you were wondering, the %s things in the string.format call are not bothered by the preprocessor, since those are letters, not numbers.


Although, safer to double them. The preprocessor turns %% into %.

i.e.


Send (string.format("'%%s %%s", GetVariable("hp"), GetVariable("maxhp")))
Send (string.format("'%%s %%s", GetVariable("ftg"), GetVariable("maxftg")))
Send (string.format("'%%s %%s", GetVariable("mana"), GetVariable("maxmana")))


- Nick Gammon

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

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Thu 11 Mar 2010 06:31 PM (UTC)
Message
Never knew that, good point!

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Kurapiira   (25 posts)  [Biography] bio
Date Reply #4 on Thu 11 Mar 2010 09:42 PM (UTC)
Message
many thanks amigos,
works like a charm.

And thanks for the info on the preprocessor
and the %% !

K.
[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.


12,088 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 HostDash]