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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Modularization Issues
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

Modularization Issues

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

Posted by Tichi   (3 posts)  [Biography] bio
Date Thu 07 May 2009 06:04 AM (UTC)
I'm having issues modularizing my lua scripts. I have a main script file, which calls my other script files (it calls system.lua, which has requires for all my other scripts). When the system is installed, it uses dofile() on various lua files which define triggers, aliases, timers, etc. Most of the time it works correctly. However, on triggers that have a script function reference (instead of using sendto.script) due to my wanting to have access to the styles, it tells me: Script name is not in the script file when I try to set the script function reference to a function in one of the other script files (a.k.a. calling prompt_capture in prompt.lua). I can use /prompt_capture and have it run the function, but it says it can't find it for the trigger. Any way around this?
[Go to top] top

Posted by Tboydston   (14 posts)  [Biography] bio
Date Reply #1 on Thu 07 May 2009 05:59 PM (UTC)
You can always use the XML <include> tag and save triggers and their needed scripts as an xml file instead of just as a lua file.

When setting up a file to be included just follow a slightly typical plugin format:
     blah blah blah>

This will load it all into the main XML file using it as if it were hard coded in the file main one to begin with.

Since you're keeping the triggers with their necessary script functions, those errors will disappear.

I'm sure somebody will be able to elaborate a bit on my suggestion, this is just what I've made work for my own uses.
[Go to top] top

Posted by Tichi   (3 posts)  [Biography] bio
Date Reply #2 on Thu 07 May 2009 11:00 PM (UTC)
Well, my main issue is that I want to keep the scripts separate in their own files. Basically, my entire system is based off of the main system.lua. You have prompt.lua, stats.lua, etc. And each of these has a settings file (with triggers and what not) such as prompt_settings.lua. A trigger in prompt_settings has reference to prompt:capture, which is defined in prompt.lua as prompt:capture(name, line, wildcards, styles). Normally, I would just set the trigger to send-to script, and put the function in the send text - this works. However, I can't find any way to get a hold of the styles of the match if I do it that way. I tend to reuse quite a few of my scripts and functions, so defining them in the triggers file results in a lot of redundant code, which I'd prefer to avoid. Anyone have any ideas as to how to get around this issue efficiently?
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Reply #3 on Fri 08 May 2009 11:29 AM (UTC)
Are you using prompt_capture or prompt:capture? I don't think the latter syntax works in the script field of a trigger or alias. You'd have to use the former and then call the latter inside, as a sort of redirection.

My system for Lusternia (http://larkin.dischai.googlepages.com/treant) is highly modularized and has no troubles with calling functions from other functions. I use the script field in only two or three places, though.
[Go to top] top

Posted by Tichi   (3 posts)  [Biography] bio
Date Reply #4 on Fri 08 May 2009 11:24 PM (UTC)
Yeah, I ended up making a trigger-redirecting function, since I don't plan to use many of the direct-function call triggers. Was just hoping there was a better way to do it, heh. Thanks guys.
[Go to top] top

Posted by Nick Gammon   Australia  (21,674 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 09 May 2009 01:56 AM (UTC)
Have you looked at the "require" function call? This loads a file once only, which sounds like what you are trying to do.

- Nick Gammon

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


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.


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 FutureQuest]