Two Scripting Issues

Post Reply
Koranna
Posts: 2
Joined: Tue Apr 06, 2010 4:17 pm

Two Scripting Issues

Post by Koranna »

Game: Lusternia
OS: Windows 7
Mudlet: 1.1.0 (I got the 1.1.1 installer from the website, but it installs 1.1.0, even after a full uninstall)

One:
I have written a custom defense display that shows either when you type defs (which just calls the displayDefenses() function), or def (which updates the defenses by doing a send("def") to the system, waiting for and deleting the output, and on the last line which is always You are protected by <num> defenses. it deletes the line then calls displayDefenses()). When I call it with defs, it displays just fine. However, when I call it with def, it displays with an extra line break in the second last line at all times. I suspect this has something to do with it displaying in the middle of output, but I can't figure it out. All the code is in the profile, and set up to best show that line break (It'll occur in the last domoth blessing line, Lesser Death I believe). If anyone has any idea why this is happening, I'd be grateful for some answers.

http://tichi.org/profile.xml

Two:
If you make a trigger on, say, the prompt, and then in that trigger's code you make a temporary trigger that also matches the prompt's code, the temporary trigger runs on the trigger line that called the code to create it. This seems out of place to me - is this how it's suppose to happen? It means that you can't set up a temporary trigger to call on the same line one after the other, which is a problem for my scripts. An example trigger is (in Lusternia):

Permanent Trigger:
Pattern: "ex-" (substring)
Code:
display("First trigger")
tempTrigger("ex-", [[display("I'm temp trigger!")]])

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

Re: Two Scripting Issues

Post by Heiko »

You have several bugs in your script. Here's the corrected version:

Code: Select all

function displayDefenses()
	fg("SeaGreen")
	echo("\n"..string.rep("*", 34).."[ ")
	resetFormat()
	echo("DEFENSES")
	fg("SeaGreen")
	echo(" ]"..string.rep("*", 34).."\n")
	resetFormat()

	local displayedDefs = {}
	local first = true
	for k, v in pairs(defTypes) do
		local position = 1
		firstDef = true
		for x, y in ipairs(v) do
			if table.contains(defenses, y) then
				if firstDef then
					if not first then
						fg("SeaGreen")
						echo(string.rep("-", 80).."\n")
						resetFormat()
					else
						first = false
					end
					echo(k.."\n")
					fg("SeaGreen")
					echo("\n"..string.rep("-", 80).."\n")
					resetFormat()
					firstDef = false
				end
				setFgColor(0, 255, 0)
				echo(y)
				resetFormat()
				echo(string.rep(" ", 19 - string.len(y)))
				if position <= 3 then
					echo(" ")
					position = position + 1
				else
					echo("\n")
					position = 1
				end
			elseif table.contains(reqDefs, y) then
				if firstDef then
					if not first then
						fg("SeaGreen")
						echo("\n"..string.rep("-", 80).."\n")
						resetFormat()
					else
						first = false
					end
					echo(k.."\n")
					fg("SeaGreen")
					echo(string.rep("-", 80).."\n")
					resetFormat()
					firstDef = false
				end
				setFgColor(255, 0, 0)
				echo(y)
				resetFormat()
				echo(string.rep(" ", 19 - string.len(y)))
				if position <= 3 then
					echo(" ")
					position = position + 1
				else
					echo("\n")
					position = 1
				end
			end
		end
		--if position ~= 1 then echo("\n") end
	end

	--[[if table.size(domoths) > 0 then
		fg("SeaGreen")
		echo(string.rep("-", 80).."\n")
		resetFormat()
		echo("Domoths\n")
		fg("SeaGreen")
		echo(string.rep("-", 80).."\n")
		resetFormat()
		for k, v in pairs(domoths) do
			echo(v.." "..k..", "..domothLines[k][v].."\n")
		end
	end]]--

	fg("SeaGreen")
	echo("\n"..string.rep("*", 80).."\n")
	resetFormat()
end
As for your second question: There are several high and low level ways to tackle your problem.
Look into multi condition triggers and line spacer patterns in particular as well as into linetriggers and the special function isPrompt().

Koranna
Posts: 2
Joined: Tue Apr 06, 2010 4:17 pm

Re: Two Scripting Issues

Post by Koranna »

I copy-pasted your code into my script, but the same error is resulting - the last line of the domoth blessings is getting an extra line break in the middle of the line, which has no line break in the table the line is being referenced from. In fact, the only difference your changes made visually (the position <=3 part is a better setup than my original) was to add extra line breaks before the --------- lines that I didn't want there. Is there no explanation for why that extra line break is showing up in the middle of my domoth blessing line, only when the line is printed from a deleteLine() trigger?

And as for the second issue, I understand that there are probably other ways to accomplish what I was describing, however, my question was and still is, does a temporary trigger created from the code of another trigger also get run on the line that the trigger that made it ran and matched on? If that is the case, what would the purpose of this be, as it seems very unintuitive to me.

Koranna

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

Re: Two Scripting Issues

Post by tsuujin »

It doesn't seem like temp triggers get run on the line that the calling script triggered on, no.

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

Re: Two Scripting Issues

Post by Heiko »

Koranna wrote:I copy-pasted your code into my script, but the same error is resulting - the last line of the domoth blessings is getting an extra line break in the middle of the line, which has no line break in the table the line is being referenced from. In fact, the only difference your changes made visually (the position <=3 part is a better setup than my original) was to add extra line breaks before the --------- lines that I didn't want there. Is there no explanation for why that extra line break is showing up in the middle of my domoth blessing line, only when the line is printed from a deleteLine() trigger?

And as for the second issue, I understand that there are probably other ways to accomplish what I was describing, however, my question was and still is, does a temporary trigger created from the code of another trigger also get run on the line that the trigger that made it ran and matched on? If that is the case, what would the purpose of this be, as it seems very unintuitive to me.

Koranna
Your script contained a logic bug. As you've commented out your domoth lines I haven't touched them. Here's the output of my version (with domoth lines).

Code: Select all

**********************************[ DEFENSES ]**********************************
Nekotai
--------------------------------------------------------------------------------
grip                
--------------------------------------------------------------------------------
Consumable
--------------------------------------------------------------------------------
acquisitio          deathsight          kingdom             mercy              
perfection          waterbreathe        waterwalk           
--------------------------------------------------------------------------------
Discernment
--------------------------------------------------------------------------------
nightsight          
--------------------------------------------------------------------------------
Stealth
--------------------------------------------------------------------------------
bracing             sneak               
--------------------------------------------------------------------------------
Miscellaneous
--------------------------------------------------------------------------------
nightwraith         
--------------------------------------------------------------------------------
Domoths
--------------------------------------------------------------------------------
Lesser Death, damage dealt to attackers of multiple guild members

********************************************************************************
and this is the output of your original script:

Code: Select all

**********************************[ DEFENSES ]**********************************
Nekotai
--------------------------------------------------------------------------------
grip                ------------------------------------------------------------
--------------------
Consumable
--------------------------------------------------------------------------------
acquisitio          deathsight          kingdom             mercy              
perfection          waterbreathe        waterwalk           --------------------
------------------------------------------------------------
Discernment
--------------------------------------------------------------------------------
nightsight          ------------------------------------------------------------
--------------------
Stealth
--------------------------------------------------------------------------------
bracing             sneak               ----------------------------------------
----------------------------------------
Miscellaneous
--------------------------------------------------------------------------------
nightwraith         ------------------------------------------------------------
--------------------
Domoths
--------------------------------------------------------------------------------
Lesser Death, damage dealt to attackers of multiple guild members
********************************************************************************

Post Reply