Trying to automate a skill with triggers

Posted by Xandler on Thu 30 Jun 2022 04:40 PM — 7 posts, 19,056 views.

#0
I have been struggling with this for what seems like weeks (I keep going back to it to see if I can get it to work)

I have no idea WHY this will not work (I don't get any error messages), it just will not fire when the conditions are met.


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="kaioken"
   keep_evaluating="y"
   match="Gravity: Normal"
   send_to="12"
   sequence="100"
  >
  <send>if GetVariable("kaiokenlevel") == 0 and GetVariable("pki") &gt;= 90 then
Send 'kaioken'
Send 'score'
else
if @pki &lt;= 20 then 
Send 'kaioken'
Send 'score'
end
end
end</send>
  </trigger>
</triggers>


Did I structure this wrong? I initially used the @variable then switched but neither version worked. Again, I get no error messages, the first half will not fire when the conditions are met.
USA Global Moderator #1
If the trigger doesn't fire then the conditions are not met. What line do you expect it to fire on?
#2
Basically, I want it to fire off this:


if GetVariable("kaiokenlevel") == 0 and GetVariable("pki") &gt;= 90 then
Send 'kaioken'
Send 'score'


Variables for kaiokenlevel which starts at 0 (So that should always be true) and when the the pki variable is at or above 90 it should fire kaioken, then score. I have actually looked in my variables window when both are true and it won't fire, however, I have tested with each variable individually and it works for the pki when that's above 90, but not kaiokenlevel when that's at 0 so I'm unsure what the issue with that variable is. The trigger I have to set up my capture of kaiokenlevel is working properly too as it captures the correct number in the variables window.
Amended on Thu 30 Jun 2022 08:35 PM by Xandler
USA Global Moderator #3
I mean what line from the game do you expect your trigger to match?

Quote:
but not kaiokenlevel when that's at 0

Are you sure it's 0 and not "0"? Please show the code where you set your variables.
Amended on Thu 30 Jun 2022 08:42 PM by Fiendish
Australia Forum Administrator #4
Quote:


if GetVariable("kaiokenlevel") == 0 and GetVariable("pki") >= 90 then
  Send 'kaioken'
  Send 'score'
else
  if @pki <= 20 then 
    Send 'kaioken'
    Send 'score'
  end
end
end



I indented it for you. There seems to be an "end" too many.

In any case you are inconsistent with your use of variables. Why use @pki and GetVariable("pki") in the same script?

An important point is that GetVariable("pki") returns a string and not a number, and in Lua strings are not converted into numbers, thus "100" would be considered less than "90", because 1 is less than 9, and in strings they are compared from left to right.

One thing to try there is to convert it to a number, eg.


if tonumber (GetVariable("kaiokenlevel")) == 0 and tonumber (GetVariable("pki")) >= 90 then
Amended on Fri 01 Jul 2022 05:27 AM by Nick Gammon
#5
I managed to figure it out with some trial and errors, I changed the code to the following:


if (@kaiokenlevel == 0 and @pki >= 90) then
Send 'kaioken'
Send 'score'
elseif (@kaiokenlevel > 0 and @pki <= 20) then
Send 'kaioken'
Send 'score'
SetVariable ("kaiokenlevel", "0")
end


That seems to have made it work, this thread can be closed now. Thanks for the input. I don't indent my code because it's easier for me to read (probably backwards to most of you) than it is when I do. Also, I used the @ and GetVariable in the same snippet as I was trying to do it off a previous trigger (not related to this) that I have that uses both (I didn't write it), was given to me via pastebin.

Either way, problem solved.
Amended on Fri 01 Jul 2022 12:21 PM by Xandler
Australia Forum Administrator #6
Yes, that will also work, because when you use variables like that the contents are literally inserted into the code (without quotes) so numbers are still numbers.