Newbie to Scripting - Trouble with Alias, Triggers, and Running Scripts

Posted by Nanners on Sat 26 Feb 2022 10:49 PM — 6 posts, 21,008 views.

#0
By looking at examples I tried to piece something together on how to script an alias that turns a trigger on, have a trigger match, and have the trigger run a script. I realize now that I might be taking bits from different areas, and though my intention was to use lua it might not be.

My goal was to make a trigger I could turn on/off that would get my character to rest if movement points fell below 120. The trigger would then disable so it would not spam rest. I could then toggle the trigger back on with the alias if I wanted. This was more a test to see if I could use some features together.

Below is what I scripted for lua.


<aliases>
 <alias
	name="ToggleMovement"
	match="moveset" -- I assume this is the command I enter
	enabled="y"
	send_to="12"
	ignore_case="y"
	sequence="100"
	>
	<send>
	enabletrigger (movement, true)
	ColourNote ("sienna", "thistle", "MOVESET")
	</send>
</alias>
</aliases>

<triggers>
<trigger_enabled="y" match="^(.*?)H (.*?)V (.*?)X" script="restore" other_back_colour="black" other_text_colour="black" sequence="100" regexp="y" name="movement"> </trigger> -- the prompt it is matching to is something like 300H 130V 2323232X then more text
</triggers>
<script>

<![CDATA[
function restore()
{
	if(%2 < 120) 
	{
		world.execute("rest");
		enabletrigger ("movement", false);
	}

}

]]>
</script>


I am a complete newbie to any coding language so I probably should have figured out each piece on it's own first. Any guidance would be appreciated.

If I can figure this out next I'll tackle how to use the wait module.

[EDIT] Code tags added.
Amended on Sun 27 Feb 2022 12:14 AM by Nick Gammon
Australia Forum Administrator #1
You have combined several ideas in your script. Sorting out what you appear to be trying to do, try copying and pasting this trigger and alias:


<aliases>
  <alias
   name="ToggleMovement"
   match="moveset"
   enabled="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>

EnableTrigger ('movement', true)
ColourNote ("sienna", "thistle", "MOVESET")

 </send>
  </alias>
</aliases>



Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.



<triggers>
  <trigger
   match="^(.*?)H (.*?)V (.*?)X"
   name="movement"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

if %2 &lt; 120 then
  Execute("rest")
  EnableTrigger ("movement", false)
end -- if

</send>
  </trigger>
</triggers>



Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


Note that Lua is case-sensitive. Your function calls must match the documentation, you cannot just type them in using all lower-case unless that is exactly how they are shown.
#2
Thanks Nick that works great! Appreciate the help (and patience). Learned a lot from your example.

The mud I play allows you to use up to two characters at the same time. So using an example someone else kindly provided I did the following and it worked (mostly)!


if %2 < 120 then
local clericworld = GetWorld ("cleric");

if clericworld then
  Send(clericworld, 'say hello warrior')
end
  Execute("say hello cleric")
  EnableTrigger ("movement", false)
end -- if


I just added the piece around sending to clericworld to the trigger and changed the execute for the world I was in to say hello cleric.

Good news is that works. Bad news if I wanted to send cast 'heal' warrior it creates an error due to the "'".

For example:


Send(clericworld, 'cast 'heal' warrior')


I also tried


Send(clericworld, '^cast \'heal\' warrior$')


No luck on both sadly. Any recommendations on how I can get it to accept the "'"?

Thanks again for all the help!
Amended on Sun 27 Feb 2022 04:22 AM by Nick Gammon
Australia Forum Administrator #3
Template:codetag
To make your code more readable please use [code] tags as described here.


Your posts are more readable with code tags around the code. I've fixed up your first couple of posts but would appreciate it if you do it yourself in future. :)
Australia Forum Administrator #4
Quote:

No luck on both sadly. Any recommendations on how I can get it to accept the "'"?


The simplest thing is to use the other quotes:


Send(clericworld, "cast 'heal' warrior")


The Programming in Lua book is well worth reading. The first edition is available free from their website:

http://www.lua.org/pil/

Here is link to the online version. Although the version we are using is a bit more modern, most of the stuff there applies to it.
#5
Haha I feel like a fool, thanks for pointing me in the right direction again.

I'll definitely check it out and think on things a little more .

Swapping ' with " worked great!