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
➜ General
➜ Require functions not working as they should when loaded
Require functions not working as they should when loaded
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Trevize
(21 posts) Bio
|
Date
| Wed 06 Dec 2006 04:34 AM (UTC) Amended on Wed 06 Dec 2006 04:36 AM (UTC) by Trevize
|
Message
| My problem is simple this. When I load an lua file with require it seem to cause some kind of a problem with script="sub". No error message shows up when loaded, but when the pattern matches and the trigger runs, it says "Trigger function "sub" not found or had a previous error.". This is -only- when I load with require. If I open my triggers in mushclient and enable the trigger "test" manually it works just like it should. If I use EnableTrigger or EnableGroup the error shows up when the pattern matches.. Can someone please explain this, its driving me nuts.. I'm trying to inplant a flexible system changing my offence depanding on what characther I'm using and not filling up the entire client with triggers and etc.
------------------------------
My main lua file loaded by the mushclient contains this and much more:
function is called and name = "assassin":
DeleteTriggerGroup("classes")
DeleteAliasGroup("classes")
DeleteTimerGroup("classes")
DeleteTemporaryAliases()
DeleteTemporaryTriggers()
classes = utils.readdir (GetInfo(57) .. "plugins\\xtcy\\classes\\*.lua") assert (classes)
for k, v in classes do
if tostring(string.gsub(k, "(%a+).lua", "%1")) == name then
require(GetInfo(57) .. "plugins\\xtcy\\classes\\" .. tostring(k))
end
end
function sub(subtext)
if subtext ~= "" then stext = subtext end
for word in string.gfind(stext, "($[#%a%d]+$[^$]+)") do
ColourTell(tostring(string.gsub(word, "$([#%a%d]+)$(.*)", "%1")), "black", tostring(string.gsub(word, "$([#%a%d]+)$(.*)", "%2")))
end
ColourTell("", "", "\n")
end
---------------------------
Assassin.lua contains this and other things.
ImportXML
[[
<triggers>
<trigger name="test" lines_to_match="2" keep_evaluating="y" match="^You prepare yourself to hypnotise your victim, (.*)\n(.*)\.$" multi_line="y" regexp="y" script="sub" send_to="12" sequence="101" group="classes">
<send>stext = "$gray$Prepares hypnosis for $white$" .. tostring("%1%2") .. "$darkgray$."</send>
</trigger>
</triggers>
]]
Ps. I've used LoadPlugin("url") before, the problem with that is that I cant use function in my main lua file with the aliases, triggers and timers which is vital for my system since its need to know balances, wielded weapons, current afflictions and so on. .ds
Many thanks to whoever can solve or atleast tell me why and what my problem is. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Wed 06 Dec 2006 07:38 AM (UTC) Amended on Wed 06 Dec 2006 07:39 AM (UTC) by Nick Gammon
|
Message
| First you can simplify a couple of things:
DeleteTriggerGroup("classes")
DeleteAliasGroup("classes")
DeleteTimerGroup("classes")
... can become:
And instead of:
classes = utils.readdir (GetInfo(57) .. "plugins\\xtcy\\classes\\*.lua") assert (classes)
... this looks neater:
classes = assert (utils.readdir (GetInfo(57) .. "plugins\\xtcy\\classes\\*.lua"))
(assert returns a non-nil value so you can simply assign it).
Quote:
function is called and name = "assassin":
As for your main problem, it is a bit unclear what you are doing exactly.
However a clue might be that the availability of a function is checked for when the trigger is added, for efficiency reasons. Thus this won't work:
- Create a trigger that has a script function "sub" (which doesn't exist)
- Later, create function "sub"
- The trigger will not find "sub" now.
What you can do is make a dummy "sub" function (this can do nothing), so that MUSHclient marks it as "available". Then later on you can reassign the actual code that "sub" does, and it will still work (this is Lua-specific). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Trevize
(21 posts) Bio
|
Date
| Reply #2 on Wed 06 Dec 2006 11:54 AM (UTC) |
Message
| Yeah I figured it might be something just like that. So I did what you say'd before I created an sub function in the lua file that is loaded with "require" and still got the problem. Only diffrence was that now (that) function was called instead of the function in my main lua file. Afer this I moved the function sub belove the function that load with "require" and then the normal function sub loads but the trigger still wont work.
I have even tried putting it as an sandbox, still wont load properly, but that way my normal sub function is called instead of the sandbox one.
The problem seem to be exactly what you stated
- Create a trigger that has a script function "sub" (which doesn't exist)
- Later, create function "sub"
- The trigger will not find "sub" now.
But why the heck does'nt it find the sub function when its in a sandbow or above the ImportXml part in the lua file.
When the trigger is created and I test it with the test trigger function in mush (ctrl+shift+f12):
You prepare yourself to hypnotise your victim, Erus Smeff Valstivar, Wraith of
Eternal Ire.\0A
It shows:
You prepare yourself to hypnotise your victim, Erus Smeff Valstivar, Wraith of
Eternal Ire.
Trigger function "sub" not found or had a previous error.
If I open the triggers in mushclient, doubleclick on the one we're working on, and press ok. Close the window, and try running the test trigger again it works:
You prepare yourself to hypnotise your victim, Erus Smeff Valstivar, Wraith of
Eternal Ire.
Prepares hypnosis for Erus Smeff Valstivar, Wraith of Eternal Ire.
Out of ideas how to make it work. There's no other way of adding triggers, alises and timers from an lua och plugin file with them having access to the main functions in my main lua file? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Wed 06 Dec 2006 05:58 PM (UTC) |
Message
|
Quote:
There's no other way of adding triggers, alises and timers from an lua och plugin file with them having access to the main functions in my main lua file?
Ah I didn't spot this as being the exact problem.
It is part of plugin design that each plugin executes in its own script space, thus you cannot load subs into a plugin and expect them to be available in the main script file (or another plugin). For one thing, they may be in different script languages.
I gather you putting most of your scripts in the main file? Thus you shouldn't use plugins to load shared subroutines. Simply "require" them into the main script space.
Or, move the scripts, triggers, etc. into a plugin, and load that. I'm not totally clear on what you are doing, but it seems you are mixing two methods here. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Trevize
(21 posts) Bio
|
Date
| Reply #4 on Wed 06 Dec 2006 06:55 PM (UTC) |
Message
| No I dont think thats what I mean.. I am already using require to do that... I'm tired of this and just want it to work and really really confused.. here's my entire lua file:
http://83.251.195.236/xtcy.lua
Dont try and load it, since its missing out on a few sandboxes.
Here's the file that I load with require:
http://83.251.195.236/assassin.lua
See function sub and class in xtcy.lua.. And see line 180 in assassin.lua.. that trigger is imported into the mushclient and there it tries to call the function sub which is in the main lua file "xtcy.lua"
I hope this helps to explain my problem, thank you | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #5 on Wed 06 Dec 2006 11:45 PM (UTC) |
Message
| I think your problem is covered in this post:
http://www.gammon.com.au/forum/bbshowpost.php?id=6369
Particularly this line:
Quote:
There is a test in the "Load World" function (which is also used for ImportXML), that it doesn't find script entry points if a plugin is doing ImportXML.
There is a suggested solution there, and this may well solve your problem. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Trevize
(21 posts) Bio
|
Date
| Reply #6 on Thu 07 Dec 2006 12:16 AM (UTC) |
Message
| Thanks a million I read the thread and found a solution it just brought up another problem with my sub function but it aint possible to fix. Will do that in the morning..
Million thanks!! | 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.
22,065 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top