Custom echo function doesn't work with triggers...

Post Reply
Erant
Posts: 12
Joined: Fri Feb 27, 2015 2:02 am

Custom echo function doesn't work with triggers...

Post by Erant »

So I have this custom echo function. It looks like this:
Code: [show] | [select all] lua
vg.echo = function(arg)
	echo("\n")
	local str = {}
	local strNumber = 1
	local strLimit = 64
	local echoString = ""
	local splitStr = string.split(arg, " ")
	arg = ""
	for i = 1, #splitStr do
		arg = arg .. splitStr[i] .. " "
		if arg:len() > strLimit then
			if #str == 0 then
				table.insert(str, strNumber, string.cut("<lavender>" .. arg .. "                       ", 79))
				str[strNumber] = str[strNumber] .. "<dark_khaki>|"
				arg = ""
				strNumber = strNumber+1
			elseif #str > 0 then 
				table.insert(str, strNumber, string.cut("<dark_khaki>|<lavender> " .. arg .. "                       ", 93))
				str[strNumber] = str[strNumber] .. "<dark_khaki>|"
				arg = ""
				strNumber = strNumber+1
			end
		end
	end
	if #str > 0 and arg:len() > 0 then
		table.insert(str, strNumber, string.cut("<dark_khaki>|<lavender> " .. arg .. "                                                         ",  93))
		str[strNumber] = str[strNumber] .. "<dark_khaki>|"
		arg = ""
	end
	if arg:len() < strLimit and #str == 0 then
		table.insert(str, strNumber, string.cut("<lavender>" .. arg .. "                                                          ", 79))
		str[strNumber] = str[strNumber] .. "<dark_khaki>|"
		arg = ""
		strNumber = strNumber+1
	end
	for i,v in ipairs(str) do
		echoString = echoString .. str[i] .. "\n"
	end           
	if #str > 0 then
		cecho("<dark_khaki>+=<orange_red> Vanguard<dark_khaki> " .. string.rep("=", 59) .. "+\n") 
		cecho("<dark_khaki>| " .. echoString)
		cecho("<dark_khaki>+" .. string.rep("=", 70) .. "+\n") 
	end
end
I'm having a really weird problem with it. If I give it a one line argument from an alias, it works fine:

lua vg.echo("Balance recovered!")

echos:
Code: [show] | [select all] lua
+= Vanguard ===========================================================+
| Balance recovered!                                                   |
+======================================================================+
However, if I set up a trigger with the same exact function call, I get this:
Code: [show] | [select all] lua
+= Vanguard ===========================================================+
| Balance recovered!                                                  
|
+======================================================================+
I really don't understand how that linebreak is getting there. The same function call echos the string correctly from an alias, the linebreak ONLY sneaks in there when it's called from a trigger. What's going on?

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

Re: Custom echo function doesn't work with triggers...

Post by Vadi »

It seems like the last | is getting pushed to a new line, are you near your word wrap limit perhaps?

Erant
Posts: 12
Joined: Fri Feb 27, 2015 2:02 am

Re: Custom echo function doesn't work with triggers...

Post by Erant »

What seems to be happening is a newline is being inserted at the end of my argument to the function, but only when done by a trigger. If I use an alias to execute the same exact code, it displays correctly. I'm about 20 characters away from my wrapwidth.

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

Re: Custom echo function doesn't work with triggers...

Post by Vadi »

I've tested it and it does not happen for me:

Code: Select all

(p) (ex) 4600h|100%, 3838m|81%, 100w%, 100e%, (d)-  

+= Vanguard ===========================================================+
| Balance recovered!                                                   |
+======================================================================+
(svo): Code ran OK, there were no results.
(ex) 4600h|100%, 3838m|81%, 100w%, 100e%, (d)-  
You see a single exit leading west.
(p) (ex) 4600h|100%, 3838m|81%, 100w%, 100e%, (d)-  
(Market): Lisbethae says, "Many items not available for sale to the public before. Clothing for 
every adventurer!"
(p) (ex) 4600h|100%, 3838m|81%, 100w%, 100e%, (d)-  
You see a single exit leading west.
+= Vanguard ===========================================================+
| Balance recovered!                                                   |
+======================================================================+
(p) (ex) 4600h|100%, 3838m|81%, 100w%, 100e%, (d)-  
So you'd need to cut down your example to a smaller issue that's replicatable and see what is going on then.

Erant
Posts: 12
Joined: Fri Feb 27, 2015 2:02 am

Re: Custom echo function doesn't work with triggers...

Post by Erant »

Weird. o.o Were you running it from an alias there? It happens with literally any one line string fed to vg.echo() in the body of a trigger, every single time. I tried on a totally clean profile and it behaved the same way. Were you testing it with 3.0 or 2.1? I'm using 2.1.

Edit: Took a screenshot. https://www.dropbox.com/s/shp8vmmo0gbtb ... 2.png?dl=0

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

Re: Custom echo function doesn't work with triggers...

Post by Vadi »

The first is the alias, the second is the trigger. I believe that was on 3.0.

Erant
Posts: 12
Joined: Fri Feb 27, 2015 2:02 am

Re: Custom echo function doesn't work with triggers...

Post by Erant »

Could be a 2.1 issue, I suppose. I'll see if I can get 3.0 to compile and test it.

Erant
Posts: 12
Joined: Fri Feb 27, 2015 2:02 am

Re: Custom echo function doesn't work with triggers...

Post by Erant »

This is indeed a 2.1 bug. Seems to be fixed in 3.0.

Post Reply