Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
Entire forum
➜ MUSHclient
➜ Lua
➜ Lua Plugin help
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Onoitsu2
USA (248 posts) Bio
|
Date
| Tue 16 May 2006 04:58 PM (UTC) Amended on Tue 16 May 2006 05:04 PM (UTC) by Onoitsu2
|
Message
| I had a spellup script in VBScript, now I am trying to port it over to Lua so all my friends can use it. I have gotten it pretty much done, and keep getting an error message...
Error number: 0
Event: Compile error
Description: [string "Plugin"]:385: unexpected symbol near `for'
Called by: Immediate execution
Line 189: Error parsing script (problem in this file)
ok line 189 is the <script> tag, so that does not help me, and any error inside that gives that line number for odd reasons unbeknownst to me.
ok my next post will be the entire plugin file ... PLEASE help...
I also figured out a substitute for the VBScript command Split("string","delimiter"), and have used that sucessfully throughout.
Edit: I am sorry for it being split so many times, but just would not let me post over that 6k character limit. | Top |
|
Posted by
| Shadowfyr
USA (1,788 posts) Bio
|
Date
| Reply #1 on Tue 16 May 2006 06:41 PM (UTC) |
Message
| Actually, the script system doesn't return the line from the start of the XML file, it returns the line "into" the script. The actual error is on line 385 of the XML file, or the 189th line of the script itself. Unfortunately, due to how you needed to split up the file to post it here, it is hard to see what line its actually talking about. Pasting it back together myself in SciTE the problem seems to be in this:
for spell in string.gfind(spellist, "[^||]+") do --Line 189 with the "for" on it.
if spell == swanted then
sfound = 1
else
if count > 0 then
snewlist = snewlist .. "||"
end
count = count + 1 --The line mine "seems" to be saying is the problem??
snewlist = snewlist .. spell
end
end
I haven't the foggiest what the problem is, since I don't program in Lua. If it was VB I would have thought maybe you left out the "each" in the "for", i.e. "for each spell in string.gfind(spelllist, "[^\]+") do", but for all I know what you are using may be correct syntax. Someone else might be able to tell you if a) I have the right block and b) what the heck is wrong in there. ;) | Top |
|
Posted by
| Nick Gammon
Australia (23,052 posts) Bio
Forum Administrator |
Date
| Reply #2 on Tue 16 May 2006 09:40 PM (UTC) |
Message
| I am puzzled about the line numbers being reported, to say the least, however what I did was copied and pasted the entire script into the Immediate window in MUSHclient, and hit Run. It then reported a problem at line 250 (??):
function somespells(sName,sLine,wildcards)
local curspells = cspells
local spellist = spells
local sfound = 0
count = 0
if v2skillcast == 1 then
Send(v2clanskill)
end if --> this is line 250
There is indeed a problem here, it should be:
end -- if
I am mystified about why the line number is so incorrect.
A few lines on, after fixing that I got an error on the line:
if sfound = 0 then
I corrected that to:
if sfound == 0 then
That got rid of the syntax errors, then it reported missing subroutine "listspells", so I changed this line to add the "s" to the function name:
function listspell(sName, sLine, wildcards)
That got it installed. Then it reported an error on this function:
function OnHelp(sName, sLine, wildcards)
Note(world.GetPluginInfo(world.GetPluginID, 3)) --> error here
end
Error: bad argument #1 to `GetPluginInfo' (string expected, got function)
This should read:
function OnHelp(sName, sLine, wildcards)
Note(world.GetPluginInfo(world.GetPluginID (), 3))
end
With those 3 changes, it installed!
I'll have to look into why the line numbers were so incorrect, however my technique of pasting the entire plugin script into the Immediate window, and trying to run it, at least gave me the correct line numbers for the errors. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,052 posts) Bio
Forum Administrator |
Date
| Reply #3 on Tue 16 May 2006 09:52 PM (UTC) |
Message
| Aha, I worked it out! :)
You had this line (added by the plugin wizard):
<include name="constants.lua"/>
The file constants.lua was inserted at the start of your script, and the script part of that is about 135 lines long.
So, to work out the error message line, you had to subtract that from the line number reported in the error. So:
385 - 135 = 250
The error was indeed around line 250.
Alternatively, since you didn't seem to be using the constants, just omit the line which included the constants.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,052 posts) Bio
Forum Administrator |
Date
| Reply #4 on Tue 16 May 2006 09:57 PM (UTC) Amended on Tue 16 May 2006 09:58 PM (UTC) by Nick Gammon
|
Message
| As a side-note, when posting with the code tag in the forum you should do a "Quote Forum Codes" operation using MUSHclient's editor. The converts things like [ to \[ otherwise if you had a subscript like [b] it would show as bold text and not as it appeared in the script. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,052 posts) Bio
Forum Administrator |
Date
| Reply #5 on Tue 16 May 2006 10:02 PM (UTC) |
Message
|
Quote:
I also figured out a substitute for the VBScript command Split("string","delimiter"), and have used that sucessfully throughout.
See this page:
http://www.gammon.com.au/scripts/doc.php?general=lua
And scroll down to:
utils.split (s, delim) - split a delimited string into a table
I think that should do it - splits a string delimited by a single character into a table. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Onoitsu2
USA (248 posts) Bio
|
Date
| Reply #6 on Wed 17 May 2006 10:46 AM (UTC) Amended on Wed 17 May 2006 10:55 AM (UTC) by Onoitsu2
|
Message
| Thank you soooo much, like i said i was porting this from a working VBScript version, and guess i missed a few conversions.
Thank you Nick for the line number info.
And as for the stringsplit command you have made, inorder to traverse it using the each method you have to use table.foreach (table, f) and call a function to recieve the values, the method I have done is more like the VBScript for each statement. AND it only splits using a single character delimiter, my way has 'unlimited' length delimiters and uses a 'regular expression style syntax'.
Thank you all for the help...
You Rock!
Laterzzz,
Onoitsu2 | Top |
|
Posted by
| Shadowfyr
USA (1,788 posts) Bio
|
Date
| Reply #7 on Wed 17 May 2006 05:49 PM (UTC) |
Message
| Didn't even think of that Nick. lol
It definitely represents a problem for using editors. Even if at some point you where to include such a thing, the editor would have to a) use something similar to a tree system to show imbedded imports or somehow correctly ID the line in the shorter version, so that adding an "Edit" button to the error dialog would correctly drop you into the editor at the error or b) just figure the right line. I think I have seen something similar of the former though, where the line containing the "import" command is without a line number, but there is a [+] below it, which when clicked shows the text of the imported part, with line numbers, in an uneditable form, with a different color, to indicate its not part of the script itself, sort of like:
-white-
1 -- My Example.
2
-grey-
import constants.lua [+]
-white-
136 -- Rest of the script
...
Or when the tree is open:
-white-
1 -- My Example.
2
-grey-
import constants.lua [-]
-green-
3 -- ----------------------------------------------------------
4 -- Error codes returned by various functions
5 -- ----------------------------------------------------------
6
7 -- These are preloaded into the "error_code" table.
8 -- Also, the descriptions are available in the "error_desc" table.
9
10 eOK = 0; -- No error
...
-white-
136 -- Rest of the script
...
Sadly, I think I have seen maybe one example total of something that did this. :( | Top |
|
Posted by
| Nick Gammon
Australia (23,052 posts) Bio
Forum Administrator |
Date
| Reply #8 on Wed 17 May 2006 10:06 PM (UTC) Amended on Wed 17 May 2006 10:07 PM (UTC) by Nick Gammon
|
Message
| Here is a nice way of getting the right line numbers:
Rather than directly putting the script into the plugin, make it a separate file like this:
<script>
<![CDATA[
dofile "C:\\spellup.lua"
]]>
</script>
Now if you get an error, the line number is exactly right, in the spellup.lua file. Once you have debugged, you can simply replace the "dofile" line with the file contents, so that you are distributing a single file.
Also, you get the correct syntax colouring (eg. in Crimson Editor) because you are editing a .lua file. |
- 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.
26,638 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top