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
➜ Working on a counting trigger, something isn't right.
|
Working on a counting trigger, something isn't right.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Engvar
(24 posts) Bio
|
| Date
| Sat 09 Mar 2019 06:12 PM (UTC) Amended on Sat 09 Mar 2019 06:13 PM (UTC) by Engvar
|
| Message
| I'm trying to make a trigger that counts every time a parry an enemy attack. Down the road, the goal will be to have a miniwindow that shows a bar with 10 segments. Every parry will fill a bar, and a full bar will let me know I can execute a charged attack, at which point the variable will be set back to 0.
This is what I have so far. It triggers on "You parry *" so that it picks up any enemy I parry. I'm trying to get it to add +1 to the variable 'parrycount' every time this happens.
<triggers>
<trigger
custom_colour="1"
enabled="y"
expand_variables="y"
ignore_case="y"
keep_evaluating="y"
match="You parry *"
regexp="y"
send_to="12"
sequence="100"
>
<send>setvariable "parrycount", CInt(getvariable("parrycount")) + 1
note getvariable("parrycount")</send>
</trigger>
</triggers>
Instead, every time I parry, I get this message.
Compile error
World: The Game I'm Playing
Immediate execution
[string "Trigger: "]:1: unexpected symbol near ','
Anyone see where I'm making my mistake? | | Top |
|
| Posted by
| Fiendish
USA (2,558 posts) Bio
Global Moderator |
| Date
| Reply #1 on Sat 09 Mar 2019 08:17 PM (UTC) Amended on Sat 09 Mar 2019 08:19 PM (UTC) by Fiendish
|
| Message
| Your pattern is not correct as a regular expression, so change
to
A regular expression for the same thing would use something like match="^You parry .+" |
https://github.com/fiendish/aardwolfclientpackage | | Top |
|
| Posted by
| Engvar
(24 posts) Bio
|
| Date
| Reply #2 on Sat 09 Mar 2019 10:22 PM (UTC) |
| Message
| Well, I updated that, and I'm still getting the same message every time a parry occurs.
<triggers>
<trigger
custom_colour="1"
enabled="y"
expand_variables="y"
ignore_case="y"
keep_evaluating="y"
match="You parry *"
regexp="n"
send_to="12"
sequence="100"
>
<send>setvariable "parrycount", CInt(getvariable("parrycount")) + 1
note getvariable("parrycount")</send>
</trigger>
</triggers>
On a positive note, now that I'm picking easier things, I'm learning a lot more. Starting with the automapper when I know nothing of Lua was a poor choice. | | Top |
|
| Posted by
| Fiendish
USA (2,558 posts) Bio
Global Moderator |
| Date
| Reply #3 on Sat 09 Mar 2019 11:05 PM (UTC) Amended on Sun 10 Mar 2019 02:37 AM (UTC) by Fiendish
|
| Message
| Oh wow, geez. I'm sorry. I completely missed the part about your error message.
Do this...
SetVariable("parrycount", tonumber(GetVariable("parrycount")) + 1)
|
https://github.com/fiendish/aardwolfclientpackage | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Sun 10 Mar 2019 (UTC) |
| Message
| It *looks* like he is using JScript, in which case there are quite a few errors. This works:
var parrycount = GetVariable("parrycount");
if (parrycount == null)
parrycount = '0';
SetVariable ("parrycount", parseInt(parrycount, 10) + 1);
Note (GetVariable("parrycount"));
Note the need to check if the variable exists, and also using parseInt rather than CInt.
It would be better to use Lua, which is the default language and is easier to use IMHO.
In that case it would read:
parrycount = GetVariable("parrycount")
-- check variable exists
if parrycount == nil then
parrycount = '0'
end -- if
SetVariable ("parrycount", tonumber(parrycount) + 1)
Note (GetVariable("parrycount"))
Note that GetVariable (and indeed all variable and function names) in Lua is case-sensitive. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Sun 10 Mar 2019 12:03 AM (UTC) |
| Message
| Lua authors often use a shortcut to test for variables that don't exist, using "or" like this:
parrycount = GetVariable("parrycount") or '0'
SetVariable ("parrycount", tonumber(parrycount) + 1)
Note (GetVariable("parrycount"))
Because of short-circuit boolean evaluation that first line evaluates to either the variable contents (if it exists) or the string '0'. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #6 on Sun 10 Mar 2019 12:08 AM (UTC) Amended on Sun 10 Mar 2019 12:12 AM (UTC) by Nick Gammon
|
| Message
|
Engvar said:
On a positive note, now that I'm picking easier things, I'm learning a lot more. Starting with the automapper when I know nothing of Lua was a poor choice.
Your code looked so unlike Lua I assumed you were using JScript. Lua variables and function names are case-sensitive. Also function calls need their arguments in parentheses unless the argument is a single string, for example:
However using parentheses also works, and is required if you have more than one argument, or the argument is not a string literal:
print ("Hello, world")
print (2 + 2, 6 + 7) -- Two arguments
There is a considerable amount of documentation about Lua on this website:
http://www.gammon.com.au/scripts/doc.php?general=lua
You might want to start with the syntax section:
http://www.gammon.com.au/scripts/doc.php?general=lua_syntax
Also the Lua online documentation is excellent. The online version is for a slightly earlier version but is still largely very relevant. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Engvar
(24 posts) Bio
|
| Date
| Reply #7 on Sun 10 Mar 2019 05:11 PM (UTC) |
| Message
| I think this is part of where I'm having trouble. I'm looking all over the forum trying to find what people have already done so I can figure out how it works, but I'm not always able to distinguish between the different languages. Lua is what I'm trying to learn.
Thank you both for your patience and help. I'll keep working on it and let you know what happens. | | Top |
|
| Posted by
| Fiendish
USA (2,558 posts) Bio
Global Moderator |
| Date
| Reply #8 on Mon 11 Mar 2019 02:56 PM (UTC) Amended on Mon 11 Mar 2019 02:57 PM (UTC) by Fiendish
|
| Message
| |
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.
28,981 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top