Error in FriendsList script

Posted by Skeric on Fri 02 Dec 2005 12:09 AM — 2 posts, 11,912 views.

#0
Hello all, I am getting errors that I don't know how to deal with here. The errors are


[string "Plugin"]:142: bad argument #2 to `ArrayImport' (string expected, got nil)
stack traceback:
	[C]: in function `ArrayImport'
	[string "Plugin"]:142: in main chunk



and


Line 220: Error parsing script (problem in this file)



and I can't seem to get what it's talking about...

Here's the script, if anyone could help me fix it, or post a fixed version, it'd be greatly appreciated.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, August 06, 2005, 6:06 AM -->
<!-- MuClient version 3.66 -->

<!-- Plugin "FriendsList" generated by Plugin Wizard -->

<muclient>
<plugin
   name="FriendsList"
   author="Keldar"
   id="c1d73077f77dc64ac21191e8"
   language="Lua"
   purpose="Find who is online"
   save_state="y"
   date_written="2005-08-07"
   requires="3.66"
   version="1.2"
   >
<description trim="y">
<![CDATA[
friendadd *                   - to add a name
friendremove *             - to remove a name
fwho                            - to list your friends online
flist                              - to display the contents of your friends list
]]>
</description>

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Triggers  -->

<triggers>
  <trigger
   group="QW_inspect"
   match="\b(@!friends_trig)\b"
   name="friend_found"
   expand_variables="y"
   regexp="y"
   repeat="y"
   script="CollectName"
   sequence="100"
  >
  </trigger>
  <trigger
   group="QW_inspect"
   match="[A-Z][a-z]+[.,]?[ ]{0,2}$"
   regexp="y"
   keep_evaluating="y"
   name="qw_gag"
   omit_from_output="y"
   script="StartStop"
   sequence="99"
  >
  </trigger>
  <trigger
   match="^\d+(?:\[[-+]\d+\]|)h, \d+(?:\[[-+]\d+\]|)m(?:, \d+(?:\[[-+]\d+\]|)e|)(?:, \d+(?:\[-+\d+\]|)w|) [c]?[e]?[x]?[k]?[d]?[b]?-$"
   name="qw_stop"
   regexp="y"
   script="FriendFindEnd"
   sequence="100"
  >
  </trigger>
</triggers>

<aliases>
<alias enabled="y" match="friendadd *" script="FriendAdd" />
<alias enabled="y" match="friendremove *" script="FriendRemove" />
<alias enabled="y" match="fwho" script="FriendFindStart" />
</aliases>
<aliases>
  <alias
   name="list_friends"
   script="ListFriends"
   match="^flist$"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  </alias>
</aliases>



<!--  Variables  -->

<variables>
  <variable name="friends_trig">Foo</variable>
</variables>

<!--  Script  -->


<script>
<![CDATA[
friends_online = {}
init_save = GetVariable("friends_save")

if not ArrayExists("friends") then
	ArrayCreate("friends")
	ArrayImport("friends", GetVariable("friends_save"), "|")
end


function BuildTrig()
	SetVariable("friends_trig", ArrayExportKeys("friends", "|"))
	SetVariable("friends_save", ArrayExport("friends", "|"))
	ret = SaveState()
	if ret == ePluginDoesNotSaveState then
		print("FriendsList plugin isn't configured to save its state.")
	elseif ret == ePluginCouldNotSaveState then
		print("FriendsList plugin couldn't save its state.")
	end
end

BuildTrig()

function FriendAdd(name, output, wildcs)
    local exists = ArrayKeyExists("friends", Capitalize(string.lower(wildcs[1])))
	if exists then
		ColourNote("yellow", "", Capitalize(string.lower(wildcs[1])).." is already on your friends list.")
	else
		ArraySet("friends", Capitalize(string.lower(wildcs[1])), "1")
		ColourNote("yellow", "", "Added "..Capitalize(string.lower(wildcs[1])).." to your friends list.")
	end
	BuildTrig()
end 

function FriendRemove(name, output, wildcs)
	if ArrayDeleteKey("friends", Capitalize(string.lower(wildcs[1]))) == eOK then
		ColourNote("yellow", "", Capitalize(string.lower(wildcs[1])).." is removed from your friends list.")
	else
		ColourNote("yellow", "", Capitalize(string.lower(wildcs[1])).." is not in your friends list.")
	end
	BuildTrig()
	
end

function ListFriends(name, output, wildcs)
	local list = ArrayExport("friends", ", ")
	if string.len(list) > 0 then
		ColourNote("yellow", "", "The following names are on your friends list currently: ")
		for k,v in ArrayListKeys("friends") do ColourNote("yellow", "", Capitalize(v)) end
	else
		ColourNote("yellow", "", "You have not added anyone to your friends list yet.")
	end
end


function Capitalize(word)
   local temp = {}
   temp[1] = string.sub(word,1,1)
   temp[2] = string.sub(word, 2)
   temp[1] = string.upper(temp[1])
   return table.concat(temp)
end

function FriendFindStart(name, output, wildcs)
	friends_online = {}
	if string.len(GetVariable("friends_trig")) == 0 then
		ColourNote("yellow", "", "You didn't add any friends to the list yet.")
		return
	end
	Send("qw")
	FriendFindStart2("", "", "")
end

function FriendFindStart2(name, output, wildcs)
	EnableTriggerGroup("QW_inspect", 1)
end 

function FriendFindEnd(name, output, wildcs)
	EnableTriggerGroup("QW_inspect", 0)
	FriendsDisplay()
end

function StartStop(name, output, wildcs)
	EnableTrigger("qw_stop", 1)
end

function CollectName(name, output, wildcs)
	EnableTrigger("qw_stop", 1)
	table.insert(friends_online, string.lower(wildcs[1]))
	
end

function FriendsDisplay()
	if table.getn(friends_online) > 0 then
		ColourNote("white", "", "The following of your friends are online:")
		for k,v in friends_online do
			ColourNote("white", "", "   "..Capitalize(v))
		end
	else
		ColourNote("white", "", "None of your friends are online currently.")
	end
	EnableTrigger("qw_stop", 0)
end


]]>
</script>


<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="FriendsList:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
function OnHelp ()
  world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script> 

</muclient>
Amended on Fri 02 Dec 2005 12:17 AM by Nick Gammon
Australia Forum Administrator #1
On the "ArrayImport" line I gather the variable "friends_save" does not exist, so it is returning nil. You could change it to this, which substitutes an empty string if the variable does not exist:


ArrayImport("friends", GetVariable("friends_save") or "", "|")