Problem with lists (solved)

Post Reply
Meridian
Posts: 6
Joined: Thu Dec 10, 2009 11:57 pm

Problem with lists (solved)

Post by Meridian »

I'm working on a set of triggers and aliases for running caravans in Imperian. I'm setting up a hard-coded list of directions for a path using a table. The first direction gets used to initiate movement, then it's popped off with listRemove() when the step is complete. After some steps, though, it seems like the next place in the list where there are 2 or more identical values is trimmed down to just 2 or 3 of those values. For instance, in the list for Aherindale, which I'll quote below, the first set of 4 "s"s gets trimmed down to 2, causing me to be way off if I can keep moving in directions that I don't intend to, and stuck on manual if I can't.

Here's the alias to start this thing: (from a towne to Ithaqua, the place that they're all returned to)

Code: Select all

if caravanDestination == "Agirni" then
	caravanList = {"s","sw","se","sw","sw","w","w","w","nw","n","n","nw","n","nw","nw","nw","w","in","u","n","n","e","u","s","e","end"}
elseif caravanDestination == "Aherindale" then
	caravanList = {"s","out","se","ne","s","s","s","s","w","sw","w","w","w","nw","w","u","sw","d","ne","d","n","n","n","n","n","n","ne","n","in","u","n","n","e","u","s","e","end"}
end
caravanDestination = "Ithaqua"
caravaning = true
echo("***Route started!***\n***To Ithaqua!***")
send("lead caravan " .. caravanList[1])
And the trigger that takes the next step when the first happens: (triggers on beginning-of-line "You lead a caravan")

Code: Select all

if caravaning == true then
	listRemove(caravanList,caravanList[1])
	if caravanList[1] == "end" then
		echo("***Route finished!***")
		caravaning = false
	else
		send("lead caravan " .. caravanList[1])
	end
end
Any suggestions?
Last edited by Meridian on Wed Apr 28, 2010 10:15 pm, edited 1 time in total.

kkerwin1
Posts: 22
Joined: Tue Apr 20, 2010 7:37 am

Re: Problem with lists

Post by kkerwin1 »

Hrm. What about creating a table, indexed by the items' positions within the list?

{{1="dir1"},{2="dir2"},{3="dir3"} ... etc}

naftali
Posts: 138
Joined: Wed Jan 20, 2010 8:42 pm

Re: Problem with lists

Post by naftali »

Dunno where you're getting that listRemove() function from. Change

Code: Select all

listRemove(caravanList,caravanList[1])
to

Code: Select all

table.remove(caravanList,1)
Aside from that your code looks fine, I use similar stuff in some of my scripts.

Meridian
Posts: 6
Joined: Thu Dec 10, 2009 11:57 pm

Re: Problem with lists

Post by Meridian »

I think I found it scattered across a few paragraphs in the manual, actually. I'll plug in the table function instead and see if it behaves better.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Problem with lists

Post by tsuujin »

yeah, a lot of people seem to be coming up with addlist and removelist lately. Should really be looked at in the manual.

kkerwin1
Posts: 22
Joined: Tue Apr 20, 2010 7:37 am

Re: Problem with lists

Post by kkerwin1 »

tsuujin wrote:yeah, a lot of people seem to be coming up with addlist and removelist lately. Should really be looked at in the manual.
Somebody with a lot of programming knowledge in Python, most likely. Lua doesn't have lists; it has tables (and damn proud of it)!! Lol.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Problem with lists

Post by tsuujin »

technically it has dictionary typed arrays.

Meridian
Posts: 6
Joined: Thu Dec 10, 2009 11:57 pm

Re: Problem with lists

Post by Meridian »

Whatever the case, switching from lists to tables seems to have fixed the problem for me. Thanks for the help!

Post Reply