Need help with converting trigger from jscript to Lua

Posted by Verve on Sun 29 Jul 2018 03:30 AM — 3 posts, 13,182 views.

#0
So, I feel like a dummy but I really can't figure this out on my own and I've been trying for days. A friend of mine gave me a script in jscript but I "script" (I mainly just patch together ghetto triggers) in Lua so I've been trying to convert this unsuccessfully.

This is for a fishing script on a MUD. The purpose is to detect the distance of the fishing line and, if it is out past 35 feet, to reel it in all the way and cast again and rinse and repeat until you get a desirable distance.


<trigger>
   enabled="y"
   group="Fishing"
   match="*You cast your hook into the * * feet from the *"
   send_to="12"
   sequence="100"
  <send>var distance = %3;
if (distance > 35) {
  DoAfter (1, 'reelin all');
  DoAfter (2, 'cast short');
}
else {
  send("reelin medium")
}</send>
</trigger>



Can anyone help me with this, pretty please?
Amended on Sun 29 Jul 2018 05:13 AM by Nick Gammon
Australia Forum Administrator #1
You haven't said what is wrong. If the trigger is not matching at all, please post (copy/paste) what the text from the MUD is.

If it is matching one problem I see is that the function is Send not send (it is case-sensitive).

Also, there is no "var" in Lua. And no braces in the way you used them.

This would be better:


distance = tonumber (%3)
if distance > 35 then
  DoAfter (1, 'reelin all')
  DoAfter (2, 'cast short')
else 
  Send("reelin medium")
end -- if
#2
Well, what's wrong is that it's in jscript and I need it in Lua! As the subject of this thread states, that's what I was asking for help with.

The trigger I posted was the original one given to me in jscript. I didn't write it. I didn't attempt to convert it for the purposes of this thread as I didn't want to embarrass myself by bungling it up.

Thanks for your help!