Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, 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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Variables not updating
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kurapiira
(25 posts) 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. | Top |
|
Posted by
| Twisol
USA (2,257 posts) 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,165 posts) 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 | Top |
|
Posted by
| Twisol
USA (2,257 posts) 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 | Top |
|
Posted by
| Kurapiira
(25 posts) 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. | 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.
15,494 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top