Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Simplifying Code Per Trigger

Simplifying Code Per Trigger

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


Posted by Tarrasque   (2 posts)  Bio
Date Wed 04 Jun 2008 01:41 PM (UTC)
Message
Okay, I am confused as to various ways to do this that would actually work. I am attempting to setup a customised cure system for Imperian and am running into an issue with a bit of optimisation for my if statements. I do not really want to put 100s of lines of code for every trigger I will have to have. So, I am wondering if there is a way to create my own custom fuction that I can use to call on for each trigger. I tried using a variable to output the function, but, I do not think it will work that way. Well, any ideas or places to point me to?
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #1 on Wed 04 Jun 2008 03:13 PM (UTC)

Amended on Wed 04 Jun 2008 03:18 PM (UTC) by Shaun Biggs

Message
You can put the custom functions into the script file and call them from the trigger. You can do this either by putting the function calls into the "send" box and set the "send to" box to script, or by filling in a function name in the script box at the bottom.

Actually, here is an older help file which shows a very basic example in VBscript. http://www.gammon.com.au/mushclient/scripting_alias_simple.htm

For Lua, you would just call the function as such:

function OnTeleport( thename, theoutput, thewildcards )
end


The first argument is the name of the trigger/alias that called the script function. The second argument is the whole line that was matched to cause the function call. Finally, the last argument is an array which will show you the wildcards within the matching line. You can look pretty much anywhere in the forums for a more detailed explanation, but this should cover the basics quickly.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Tarrasque   (2 posts)  Bio
Date Reply #2 on Wed 04 Jun 2008 06:14 PM (UTC)
Message
I noticed this feature earlier, but, I could not get it to work properly. I will look into it a bit more, however, can you only use one outside function with this feature?

Or is it that you put them all in one text file and they get called upon when used?

Is it simple enough to use variables that are within MUSH and change them without issue?

Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 04 Jun 2008 09:59 PM (UTC)
Message
You certainly should be able to write a lengthy script, without using lots of IF statements. In Lua in particular, the use of tables can greatly simplify stuff like curing systems, because you simply do a table lookup.

I suggest you initially read http://mushclient.com/scripting - there is a lot of detail there about setting up scripts.

For a lengthy system I would use a script file, and not put code in each trigger.

I would also use Crimson Editor to edit the script file. That lets you have the editor window open on one side. The post below describes various tricks you can use to optimize this, such as syntax-colouring MUSHclient script functions:

http://www.gammon.com.au/forum/?id=8692


Once you have a script file, you can make "helper" functions that other ones call, pretty much without limit.

Search this forum for "Imperian" and "curing system". There have been quite a few posts about it already, and they at least can be a guideline for you. Some are in VB, but more recent ones use Lua, and systems of tables of afflictions, cures, herbs, prioritizing the cure and so on.

Quote:

Is it simple enough to use variables that are within MUSH and change them without issue?


Yes, there have been various posts about that.

It is probably easier and faster to use straight Lua variables most of the time, as the conversion isn't needed then. However Lua script variables are lost every time you reload the script file, or close the world. The post below describes how you can easily treat MUSHclient variables as if they are Lua variables:

http://www.gammon.com.au/forum/?id=4904



Below is a post about serializing variables. That is, loading MUSHclient variables into Lua variables at the start of a session, and converting them back for saving to disk at the end:

http://www.gammon.com.au/forum/?id=4960

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


17,256 views.

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

Go to topic:           Search the forum


[Go to top] top

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