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
➜ (resolved) Unable to create timer in function called by Execute! :(
(resolved) Unable to create timer in function called by Execute! :(
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| j0nas
(56 posts) Bio
|
Date
| Sat 20 Sep 2008 03:16 AM (UTC) Amended on Sat 20 Sep 2008 03:19 AM (UTC) by j0nas
|
Message
| I'm using the Execute-trick to trigger plugin-callbacks in my main, non-plugin code. Unfortunately it appears that I'm unable to add any timers in a thread that has been created by an Execute-call.
A good way to illustrate my problem is:
/Execute("/AddTimer(\"look\", 0, 0, 2, \"\", timer_flag.Enabled + timer_flag.OneShot + timer_flag.Temporary, \"\")")
Is there any way to fix or work around this, other than moving all my code into a plugin?
Edit: I am using 4.27, but I am probably going to downgrade to the last version using the old spellchecker, so if that's a solution to this problem... :) | Top |
|
Posted by
| WillFa
USA (525 posts) Bio
|
Date
| Reply #1 on Sat 20 Sep 2008 04:36 AM (UTC) |
Message
| It's a syntax problem. :)
/Execute("/AddTimer('look', 0, 0, 2, 'look', timer_flag.Enabled + timer_flag.OneShot + timer_flag.Temporary, '')")
works.
Execute("/AddTimer('look', -- the Label
0, --hours
0, --minutes
2, --seconds
'look', -- send field. here's your problem.
timer_flag.Enabled + timer_flag.OneShot + timer_flag.Temporary, --flags
'' --function in world's script file.
)")
| Top |
|
Posted by
| j0nas
(56 posts) Bio
|
Date
| Reply #2 on Sat 20 Sep 2008 12:01 PM (UTC) |
Message
| You're right, thanks for correcting me. My issue remains, though perhaps it's not related to Execute. I'll dig deeper and see if I can find the cause. | Top |
|
Posted by
| j0nas
(56 posts) Bio
|
Date
| Reply #3 on Sat 20 Sep 2008 12:16 PM (UTC) |
Message
| My code is a lot more complex than the provided example, and in examining my issue further I've found that I get an errorcode "eScriptNameNotLocated (30009) Script name is not in the script file" when executing AddTimer under some circumstances. I know this isn't so, the script name exists, I think there's some kind of namespace issue perhaps.
Can I ignore the check AddTimer is performing here, to force it to do what I want? | Top |
|
Posted by
| j0nas
(56 posts) Bio
|
Date
| Reply #4 on Sat 20 Sep 2008 12:46 PM (UTC) Amended on Sun 21 Sep 2008 01:15 AM (UTC) by j0nas
|
Message
| To reproduce the problem I'm having, two files are necessary. A plugin, and a main script file. They look like this:
--- Plugin ---
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="PluginAddTimerTest"
author="-"
id="788b9fdcf934fecbb21e5306"
language="Lua"
purpose="-"
date_written="2008-09-19"
requires="3.80"
version="1.0"
>
</plugin>
<script>
<![CDATA[
Execute("/addTimerTestTrigger()")
]]>
</script>
</muclient>
-- End Plugin ---
--- Main Script ---
local totalMessage = "";
testCallbacks = {}
function partialMessage(message)
if type(message) == "boolean" then
if message then
message = "true"
else
message = "false"
end
end
if type(message) == "number" then
message = "" .. message
end
if not(type(message) == "string") then
message = "<" .. type(message) .. ">"
end
totalMessage = totalMessage .. message
end
function message(message)
partialMessage(message)
print("[script] " .. totalMessage)
totalMessage = ""
end
function addTimerTestTrigger()
if testCallbacks.AddTimerTest then
for i,o in pairs(testCallbacks.AddTimerTest) do
o()
end
end
end
function timedEvent()
message("TimedEvent triggered!")
end
function addTimerTest()
message("AddTimer returns: " .. AddTimer('', 0, 0, 2, '', timer_flag.Enabled + timer_flag.OneShot + timer_flag.Temporary, 'timedEvent'))
end
testCallbacks.AddTimerTest = testCallbacks.AddTimerTest or {}
table.insert(testCallbacks.AddTimerTest, addTimerTest)
--- End Main Script ---
The code may look a little strange, but remember that it is taken out of a larger context. To reproduce the fault, install the script file and add the plugin, then try the following input(input marked with '>', output follows):
>/addTimerTestTrigger()
[script] AddTimer returns: 0
[script] TimedEvent triggered!
/Execute("/addTimerTestTrigger()")
[script] AddTimer returns: 0
[script] TimedEvent triggered!
/ReloadPlugin("PluginAddTimerTest")
[script] AddTimer returns: 30009
Again, MUSHclient 4.27. Is there anything I can do to fix this?
Edit: Tried to format the code a little bit better, but initial tabs and spaces seem to be ignored. Maybe if I knew the forum's markups, but... :) | Top |
|
Posted by
| j0nas
(56 posts) Bio
|
Date
| Reply #5 on Sun 21 Sep 2008 01:13 AM (UTC) |
Message
| A similar experiment with EnableTrigger gives me 30005, again while I know that the named trigger exists within the main script. It seems clear that the Executed functions are still working with the environment from the Executing plugin, despite having moved to the main script.
This is really making it very, very hard to work with callbacks in the main code. Is there something I can do about it, other than to start developing in plugins? | Top |
|
Posted by
| Nick Gammon
Australia (23,159 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sun 21 Sep 2008 01:33 AM (UTC) |
Message
| Plugins and the main script are in different script spaces. They can even be in different languages (eg. VBscript and Lua). Also triggers, aliases, timers are in special plugin areas, not in the main world area. Thus a plugin cannot enable a main world trigger, or vice-versa.
This is all part of the modular design of plugins.
I would encourage you to develop inside plugins - in most cases you can do preliminary testing in the main script, and then use the Plugin Wizard to turn that into a plugin very easily. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| j0nas
(56 posts) Bio
|
Date
| Reply #7 on Sun 21 Sep 2008 01:44 AM (UTC) |
Message
| This whole problem stems from the fact that I can't use callbacks in the main script. If I could do that I would have no need for any plugins at all, is it possible to make that happen somehow, without the plugin-reroute through Execute? | Top |
|
Posted by
| Nick Gammon
Australia (23,159 posts) Bio
Forum Administrator |
Date
| Reply #8 on Sun 21 Sep 2008 02:26 AM (UTC) |
Message
| Your example script works in version 4.37. I noted in the other thread you made that Execute now executes in global script space from version 4.29 onwards. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| j0nas
(56 posts) Bio
|
Date
| Reply #9 on Sun 21 Sep 2008 08:04 PM (UTC) |
Message
| |
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.
23,650 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top