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?
Simplifying Code Per Trigger
Posted by Tarrasque on Wed 04 Jun 2008 01:41 PM — 4 posts, 22,645 views.
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:
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.
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.
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?
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?
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.
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
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?
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