Working on a counting trigger, something isn't right.

Posted by Engvar on Sat 09 Mar 2019 06:12 PM — 9 posts, 30,699 views.

#0
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?
Amended on Sat 09 Mar 2019 06:13 PM by Engvar
USA Global Moderator #1
Your pattern is not correct as a regular expression, so change
regexp="y"

to
regexp="n"


A regular expression for the same thing would use something like match="^You parry .+"
Amended on Sat 09 Mar 2019 08:19 PM by Fiendish
#2
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.
USA Global Moderator #3
Oh wow, geez. I'm sorry. I completely missed the part about your error message.

Do this...



SetVariable("parrycount", tonumber(GetVariable("parrycount")) + 1)
Amended on Sun 10 Mar 2019 02:37 AM by Fiendish
Australia Forum Administrator #4
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.
Australia Forum Administrator #5
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'.
Australia Forum Administrator #6
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:



print "Hello, world"


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.
Amended on Sun 10 Mar 2019 12:12 AM by Nick Gammon
#7
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.
USA Global Moderator #8
If you're trying to learn Lua, I suggest this thread:

https://www.gammon.com.au/forum/?id=13912&reply=1#reply1