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.
Entire forum
➜ MUSHclient
➜ General
➜ Alias needs to be called twice, to call script and set correct values?
Alias needs to be called twice, to call script and set correct values?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Winddancer
(26 posts) Bio
|
Date
| Mon 13 Feb 2023 10:11 AM (UTC) Amended on Mon 13 Feb 2023 12:14 PM (UTC) by Winddancer
|
Message
| In my mud, you get rewarded for scalping and handing in humanoid mobs. Depending on their difficulty, these scalps are worth different amounts of currency.
As there are different denominations, to the base of 16, calculating the total sum isn't that easy. Gold coins, silver coins, bronze coins and copper coins are used.
I did set up triggers that add the amount of copper coins a scalp is worth to a global variable, bounty_amount.
What I now wish to do, is get the amount in gold, silver, bronze and coppers based on the value of that global variable.
The lua script looks as follows:
function CoppersToCoinage(x)
local i=0
SetVariable("gold_coins",0)
SetVariable("silver_coins",0)
SetVariable("bronze_coins",0)
SetVariable("copper_coins",0)
SetVariable("rest_for_sc",0)
SetVariable("rest_for_bc",0)
Note("x =" .. x .. " i=" .. i)
i = x % 4096
SetVariable("rest_for_sc",i)
i = (x - i) / 4096
SetVariable("gold_coins",i)
i = GetVariable("rest_for_sc") % 256
SetVariable("rest_for_bc",i)
i = (GetVariable("rest_for_sc") - i ) / 256
SetVariable("silver_coins",i)
i = GetVariable("rest_for_bc") % 16
SetVariable("copper_coins", i)
i = (GetVariable("rest_for_bc") -i ) / 16
SetVariable("bronze_coins",i)
end -- CoppersToCoinage
When I change the global value and call the alias that converts the alias, I get the correct value for the global variable bounty_amount, but the values for the different coin types reflect the value of the time when I last called the alias.
E.g.
I set the global variable to 4097 and call the alias twice, just to overwrite everything that might have been stored in the variables and I get the following output:
x =4097 i=0
Expected bounty - 1 gc 0 sc 0 bc 1 cc
When I now change the value for x to 8375 and call the alias _once_, I get this output:
x =8375 i=0
Expected bounty - 1 gc 0 sc 0 bc 1 cc
Calling the alias a second time, the output changes to:
x =8375 i=0
Expected bounty - 2 gc 0 sc 11 bc 7 cc
The alias I use to call looks like this:
<alias
match="MyBounty"
enabled="y"
expand_variables="y"
group="statistics"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>CoppersToCoinage(@bounty_amount)
ColourNote ("#0AFF0A", "#1E1E1E", "Expected bounty - " .. "@gold_coins" .. " gc " .. "@silver_coins" .. " sc " .. "@bronze_coins" .. " bc "
.. "@copper_coins" .. " cc")</send>
</alias>
What do I need to change in order to have to call the alias only once to show the correct values? | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #1 on Mon 13 Feb 2023 11:00 AM (UTC) |
Message
| Variables used in an alias like you have (@copper_coins) are evaluated once before the start of execution of the script. Calling CoppersToCoinage inside the alias is too late.
You need to use GetVariable instead, rather than inlining the variables like you have.
ie. Instead of: "@gold_coins", use GetVariable ("gold_coins") and so on for the other ones. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
4,258 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top