[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Newbie to Scripting - Trouble with Alias, Triggers, and Running Scripts

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

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Nanners   (3 posts)  [Biography] bio
Date Sat 26 Feb 2022 10:49 PM (UTC)

Amended on Sun 27 Feb 2022 12:14 AM (UTC) by Nick Gammon

Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 27 Feb 2022 12:27 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nanners   (3 posts)  [Biography] bio
Date Reply #2 on Sun 27 Feb 2022 03:09 AM (UTC)

Amended on Sun 27 Feb 2022 04:22 AM (UTC) by Nick Gammon

Message
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!
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sun 27 Feb 2022 04:23 AM (UTC)
Message
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. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 27 Feb 2022 04:27 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nanners   (3 posts)  [Biography] bio
Date Reply #5 on Sun 27 Feb 2022 04:40 AM (UTC)
Message
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!
[Go to top] top

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.


10,503 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]