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
➜ Modularization Issues
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Tichi
(3 posts) Bio
|
Date
| Thu 07 May 2009 06:04 AM (UTC) |
Message
| 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? | Top |
|
Posted by
| Tboydston
(14 posts) Bio
|
Date
| Reply #1 on Thu 07 May 2009 05:59 PM (UTC) |
Message
| 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:<muclient>
<triggers>
<trigger
blah blah blah>
</trigger>
</triggers>
<script>
</script>
</muclient>
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. | Top |
|
Posted by
| Tichi
(3 posts) Bio
|
Date
| Reply #2 on Thu 07 May 2009 11:00 PM (UTC) |
Message
| 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? | Top |
|
Posted by
| Larkin
(278 posts) Bio
|
Date
| Reply #3 on Fri 08 May 2009 11:29 AM (UTC) |
Message
| 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. | Top |
|
Posted by
| Tichi
(3 posts) Bio
|
Date
| Reply #4 on Fri 08 May 2009 11:24 PM (UTC) |
Message
| 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #5 on Sat 09 May 2009 01:56 AM (UTC) |
Message
| 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 | 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.
19,356 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top