Unknown Error

Post Reply
Sani
Posts: 15
Joined: Thu Jan 21, 2010 6:35 pm

Unknown Error

Post by Sani »

I'm recieving this error but the place it points too is just a bit above my head.
Code: [show] | [select all] lua
LUA: ERROR running script New Trigger (Trigger1) ERROR:mudlet-lua\lua\GUIUtils.lua:730: bad 
argument #1 to 'split' (string expected, got nil)
Anyone any clues on whats causing it?

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Unknown Error

Post by Vadi »

A string.split that was given nothing to split

Sani
Posts: 15
Joined: Thu Jan 21, 2010 6:35 pm

Re: Unknown Error

Post by Sani »

Congratulations, you have been promoted to the rank of Captain Obvious.

This might be tied into it (seems like the function its referring to involves colours). Signing into Achaea and sending messages both cause Mudlet to crash, if i comment out getFgColor() then it works fine (well, no colour but no crashing either).
Code: [show] | [select all] lua
--Copy Lines and Foreground Colour
function Store_Lines(line)
	
	--select/copy colour/store to table
	selectString(matches[2],1)
	r,g,b = getFgColor()
	
	if r and g and b then
		table.insert(Main_Lines, {raw_line = matches[2], red = r, green = g, blue = b, prefix = false, suffix = false, args = false})
	else
		table.insert(Main_Lines, {raw_line = matches[2], red = false, green = false, blue = false, prefix = false, suffix = false, args = false})
	end
	--Hide Line
	deleteLine()
end
end
Both messages and the sign-in screen have empty lines, could be the cause?

EDIT:
Tested it with "ii" too, which also contains blank lines and the same crash occurs. Guess it could be selectString too if the line is just empty space.

Go Captain Obvious, use your obvious powers!!!

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Unknown Error

Post by Yetzederixx »

Could start with 1 not being a douche, and 2 getting rid of the extra end in your script, but that's just me.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Unknown Error

Post by Heiko »

You need to check the return value of selectString() to find out if an error occurred i. e. an invalid or impossible selection. If you use functions that operate on an undefined selection, the behavior is undefined and Mudlet may even crash. Usually, I've added safety code that traps those exceptions and silently ignores those cases, but obviously not in this case. I'll look into this and fix it if necessary.

PS: Your local variable "line" overshadows the built in global "line" that holds the current line as a string value.

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Unknown Error

Post by Yetzederixx »

I've noticed at least two occurances of people overwriting global variables on accident, perhaps a new global var access scheme is in order? Even just prefacing them with an _ or something to keep people from messing them up might help out.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Unknown Error

Post by Vadi »

I wouldn't like to be using _line and etc all over. They just learn quickly upon discovering the error, eventually the knowledge will spread so support for discovering this source of error will be quick. We'll do a better job of describing these special variables in the manual as well.

I think this sort of education and ease of use will trump the added complexity, personally.

In this case especially, since line is a local, all that means is that he won't be able to access the global line directly - which, if he knows about and wants to access, he'd either change his local then or use _G.line. So it's a non-issue in this example.

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Unknown Error

Post by Iocun »

Also, tons of people have already used global variables like line all over the place in their scripts. They'd all have to go around and change things again - possibly after a period of not realizing this had changed and getting quite frustrated at why their scripts no longer work. It might cause more headaches than it would prevent.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Unknown Error

Post by Heiko »

No, this is not going to happen because Mudlet's #1 dogma is to always stay backward compatible.
What we should look into, however, is that internal variables of the Lua API should be renamed to something that is not likely to be chosen as variable names by end users. This won't affect many places anyways.

Post Reply