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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Problems with OnPluginConnect

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Problems with OnPluginConnect
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Wed 22 Apr 2009 12:26 AM (UTC)  quote  ]
Message
Right. I fixed it by changing it to "if v.version then", also replacing the set-to-nil with an "if i ~= "version" in the inner loop.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 22 Apr 2009 12:08 AM (UTC)  quote  ]
Message
Yes, a bit tricky. :)


v = mods[m]
    if v then
      nexus_opts[m] = v.version


v is a table, and tables are passed by reference, not by value.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Wed 22 Apr 2009 12:02 AM (UTC)  quote  ]
Message
I discovered the problem, by adding one more Note() in a key location. :P I'm setting 'v.version' to nil in EnableModule, but apparently 'v' really references 'mods[m]', and is not actually a copy, so by unsetting v.version I'm actually killing it the next time I try to set that module, whether during the same connection or during a later one. >_<

Thanks for the help, heh. It wasn't a very obvious problem I guess.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 21 Apr 2009 08:48 PM (UTC)  quote  ]
Message
And what are your debugging displays showing?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Tue 21 Apr 2009 07:37 AM (UTC)  quote  ]

Amended on Tue 21 Apr 2009 07:38 AM (UTC) by Twisol

Message
Word for word. Given, I removed some comments and functions that weren't even used at all (SendATCP and the mods.<module>.<command> functions; none of my plugins use those), but apart from that I didn't add any extra 'local's or anything. The only reason I removed stuff at all was to fit the X000-character limit on posts.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 21 Apr 2009 07:24 AM (UTC)  quote  ]
Message
Is your plugin exactly what you posted here? If you start adding "local" here and there it can completely change how it will work.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 21 Apr 2009 07:23 AM (UTC)  quote  ]
Message
Some test plugins I just wrote seem to indicate that the BroadcastPlugin and CallPlugin functions work exactly as I expected, even if you disconnect and reconnect.

Exactly what are your debugging displays showing? Is EnableModule doing what it should and putting things into the nexus_opts table? If so, I don't see why it should be empty afterwards.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Tue 21 Apr 2009 06:58 AM (UTC)  quote  ]
Message
Quote:
You are redefining packet here (creating a new local variable of the same name). I think it is OK to do it, but it is confusing.

You're probably right, though that code was there already. I think the idea is that we're replacing the old packet with the ATCP-less packet.


Quote:
What do you mean by that exactly? What variable/table is being set or not set, and how do you know this?

I checked nexus_opts after BroadcastPlugin(0, "") and it was empty, and I also put a Note() in OnBroadcastPlugin of one of my ATCP-using plugins that shows that, yes, it is indeed receiving the broadcast (and responding). I also put Note()s in EnableModule to check what was going on in there.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 21 Apr 2009 06:46 AM (UTC)  quote  ]
Message
Quote:

I've had strange experiences with needing arbitrary amounts of slashes before the \n, and when I used \10 at some random point in time it worked, so it became a habit.


If you use send-to-script, then \n gets expanded to a newline before it hits the script engine, and thus may cause problems (eg. unterminated literal strings). However \10 would not be have so expanded.

But when you move your scripts to a script file, then this pre-expansion is not done, and you can just code in the normal way.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 21 Apr 2009 06:34 AM (UTC)  quote  ]
Message
Personally I think this is confusing:


  local packet, atcp, parsed = parseATCP(packet)


You are redefining packet here (creating a new local variable of the same name). I think it is OK to do it, but it is confusing.

Quote:

... no modules are enabled even though I know the broadcast is being responded to ...


What do you mean by that exactly? What variable/table is being set or not set, and how do you know this?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Tue 21 Apr 2009 04:18 AM (UTC)  quote  ]
Message
Whew, lots of replies.

Quote:

if type(lines) == "string" then
lines = utils.split(lines, ",")
elseif type(lines) ~= "table" then
error("Invalid argument to EnableModule: " .. lines .. "\10")
end
-- lines should be a table at this point

The argument should come in as either a string or a table. If it's a string, I convert it to a table. I don't need to check that, because I know it's already a table. If it's not a string, it checks the elseif. If it's not a table already, I don't care what it is, it's wrong! ;)

Quote:

This is the END-OF-RECORD option.

Ah, thanks. Didn't particularly know what it was for or why I needed to watch for it in the packets, since I based this plugin off of another.


Quote:

BTW, \10 is the newline character, so it is more usual to use \n.

In any case I don't think you need it, error messages are not normally terminated by a newline, Lua adds that anyway.

I've had strange experiences with needing arbitrary amounts of slashes before the \n, and when I used \10 at some random point in time it worked, so it became a habit. Not technically the best way to start a habit, I suppose.




Anyways, I still haven't discovered why it's not working depending on how many times I've called OnPluginConnect. It only seems to work the first time I open the world and connect, which implies that something's up with my 'mods' table, and I'm printing the contents of 'mods' every time I connect, so nothing's off there...

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 21 Apr 2009 03:36 AM (UTC)  quote  ]
Message
Quote:

if type(lines) ~= "table" then
error("Invalid argument to EnableModule: " .. lines .. "\10")
end


In fact, this is a good use for assert, ie.


assert (type (lines) == "table", "Invalid argument to EnableModule: " .. lines)


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 21 Apr 2009 03:35 AM (UTC)  quote  ]
Message
Quote:

error("Invalid argument to EnableModule: " .. lines .. "\10")



BTW, \10 is the newline character, so it is more usual to use \n.

In any case I don't think you need it, error messages are not normally terminated by a newline, Lua adds that anyway.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 21 Apr 2009 03:32 AM (UTC)  quote  ]
Message
Quote:

["IAC WILL EOR"] = "\255\251\025", -- ???


See: http://www.faqs.org/rfcs/rfc885.html

This is the END-OF-RECORD option.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 21 Apr 2009 03:30 AM (UTC)  quote  ]
Message
Also, this works, but is a different style to what I use elsewhere:


EnableModule = function(lines)
  -- blah blah
end -- function EnableModule


I prefer the syntactic sugar that makes it clearer we are starting a function definition:


function EnableModule (lines)
  -- blah blah
end -- function EnableModule


For me, the keyword "function" stands out more at the start of the line.

- 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.


4,047 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]