Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Attempting to use wait to wait for a particular line and failing

Attempting to use wait to wait for a particular line and failing

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 

Posted by Lilija   (9 posts)  Bio
Date Reply #15 on Tue 03 Aug 2010 08:30 AM (UTC)
Message
Hate to necro this thread, but having an issue that did't exist a few saves ago with my script. Saving as a .lua file, and importing into Mushclient. Attempting to create a function with the following code.



     function TemperStats (MaximumStat, MinimumStat, TemperStatValue, TemperStat, TemperWeaponType)
	  if (TemperStatValue \> MaximumStat or TemperStatValue \< MinimumStat) then
       ColourNote ("white", "red", TemperWeaponType .. "s have a minimum " .. TemperStat .. " of " .. MinimumStat .. " and a maximum " .. TemperStat .. " of " .. MaximumStat .. "!")
      else
       ColourNote ("white", "green", "Tempering value for " .. TemperStat .. " is " .. TemperStatValue .. ".")
	   SetVariable ("temper_" .. TemperStat, TemperStatValue)
      end -- if
     end -- function


For some reason, the less than symbol seems to be messing the whole thing up. I previously had used \< with no issue importing, but now I'm given an error that says "Attribute name must start with letter or underscore, but starts with ")"". Suppose I could solve this issue if I were to use &lt; instead of the less than symbol, but that seems like a lot of work. Is there something completely obvious that I'm missing? I feel like that's the case.
Top

Posted by Nick Gammon   Australia  (23,052 posts)  Bio   Forum Administrator
Date Reply #16 on Tue 03 Aug 2010 09:16 AM (UTC)
Message
The syntax:


if (TemperStatValue \> MaximumStat or TemperStatValue \< MinimumStat) then


isn't valid Lua. Do you mean:


if (TemperStatValue > MaximumStat or TemperStatValue < MinimumStat) then


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lilija   (9 posts)  Bio
Date Reply #17 on Wed 04 Aug 2010 04:12 AM (UTC)

Amended on Wed 04 Aug 2010 04:15 AM (UTC) by Lilija

Message
Perhaps I do mean what you posted Nick. Suppose it'd be helpful if I include all of what I'm doing.



   --This allows the user to set what stats they want to temper to.  If they go beyond maximums and minimums, it will return an error.
   <alias
    name="lil_forger_temperstats"
	match="^\s*temper\s+(damage|precision|speed)\s+(\d+)\s*$" 
	enabled="y"
	group="Lil_Forger_Suite"
	regexp="y"
	send_to="12"
	ignore_case="y"
	sequence="100"
   >
    <send>
	
     --Setting a local variable for the weapon type taken from the Lil_Forger_tempertype alias
	 
	 local WeaponType
	 WeaponType = GetVariable("weapon_type")
	 
	 --This function is used to evaluate the user's input.  It takes five arguments, the maximum, minimum and user given numbers for the particular stat, said stat, and the weapon type.  It then evaluates the relevant numbers, and if they meet the conditions sets an appropriate variable.  If they don't, it returns an error message that tells them what the minimum and maximum values for the particular stat is.

     function TemperStats (MaximumStat, MinimumStat, TemperStatValue, TemperStat, TemperWeaponType)
	  if (TemperStatValue \> MaximumStat or TemperStatValue \< MinimumStat) then
       ColourNote ("white", "red", TemperWeaponType .. "s have a minimum " .. TemperStat .. " of " .. MinimumStat .. " and a maximum " .. TemperStat .. " of " .. MaximumStat .. "!")
      else
       ColourNote ("white", "green", "Tempering value for " .. TemperStat .. " is " .. TemperStatValue .. ".")
	   SetVariable ("temper_" .. TemperStat, TemperStatValue)
      end -- if
     end -- function
	 
--Start of the alias's logic.
	 
	 if string.lower("%1") == "damage" then
	  if (WeaponType == "rapier" or WeaponType == "hammer") then
	   TemperStats (180, 35, %2, "damage", WeaponType)
	  else
	   ColourNote ("white", "red", "You have to set the type of weapon you want to temper first.  Use the command [temper type X] where X is one of the types of weapons (rapier, klangaxe, katana, etc.)")
	  end -- if
	 elseif string.lower("%1") == "precision" then
	  if (WeaponType == "rapier" or WeaponType == "hammer") then
	   TemperStats (235, 85, %2, "precision", WeaponType)
	  else
	   ColourNote ("white", "red", "You have to set the type of weapon you want to temper first.  Use the command [temper type X] where X is one of the types of weapons (rapier, klangaxe, katana, etc.)")
	  end -- if
	 elseif string.lower("%1") == "speed" then
	  if (WeaponType == "rapier" or WeaponType == "hammer") then
	   TemperStats (280, 139, %2, "speed", WeaponType)
	  else
	   ColourNote ("white", "red", "You have to set the type of weapon you want to temper first.  Use the command [temper type X] without the brackets where X is one of the types of weapons (rapier, klangaxe, katana, etc.)")
	  end -- if
	 end -- if
	</send>
   </alias>


My understanding is that if it's inside an alias/would be inside Mushclient's command box for making a new alias, the <, >, ", and other similar characters need to be escaped. What really kills me about this is that it worked just fine about a week ago, and now suddenly doesn't want to. Also, removing the \s still gives me the same error. I'm pretty sure it's just a dumb mistake on my part somewhere, so thanks in advance for being patient and showing dumb ol' me the light.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #18 on Wed 04 Aug 2010 04:46 AM (UTC)
Message
Yeah, just replace the <'s with &lt; (and & with &amp; if any). The problem is that the exported format is XML, and those two characters are considered special. The XML file itself doesn't care what the content it holds is, so it can't, say, give Lua special syntactic treatment.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,052 posts)  Bio   Forum Administrator
Date Reply #19 on Wed 04 Aug 2010 05:29 AM (UTC)
Message
I don't get this line still:


if (TemperStatValue \> MaximumStat or TemperStatValue \< MinimumStat) then


If it went in "as is" then Lua will object to the \> part - that doesn't make sense.

However the XML import is likely to complain anyway about the < not being a valid element.

Is this from an alias that already exists? I don't quite understand where the stuff you have posted comes from. If you used MUSHclient's "alias copy" then it would have converted the < into &lt;, so I am guessing you didn't do that.

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lilija   (9 posts)  Bio
Date Reply #20 on Wed 04 Aug 2010 05:38 AM (UTC)
Message
It's just a file I'm writing in Notepad++. What's funny is that the ONLY thing that causes that line to error is the < . If I remove that and the values it's comparing, the line works perfectly fine, \> and all. I'll just use &lt; , suppose my question was just more along the lines of why does escaping > seem to work and < doesn't.
Top

Posted by Nick Gammon   Australia  (23,052 posts)  Bio   Forum Administrator
Date Reply #21 on Wed 04 Aug 2010 06:11 AM (UTC)
Message
Ah OK, I start to see...

In this line:


if (TemperStatValue \> MaximumStat or TemperStatValue \< MinimumStat) then


In the Send box (which you are using) escape sequences are converted (eg. \n becomes a newline, \t becomes a tab etc.).

However an unrecognized sequence simply becomes itself, so for example \< becomes < and \> becomes >.

Thus, as far as Lua is concerned all you have done is this:


if (TemperStatValue > MaximumStat or TemperStatValue < MinimumStat) then


So the backslashes effectively do nothing (except confuse me). <grin>

Having got past the backslashes, when importing XML, the characters '&' and '<' in particular are important, because they "start" something. For example:


<alias>
&lt;


The '>' symbol isn't quite as important - it finishes a sequence like <alias> but on its own doesn't do a huge amount of harm.

So, the < definitely has to be turned into &lt; if you are going to import things this way.

But if you are going to edit in Notepad, you can copy and paste *directly from the Send box* and you don't need to muck around converting the < and > symbols.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #22 on Wed 04 Aug 2010 01:18 PM (UTC)
Message
Something else you may want to try is wrapping the content in a CDATA section. A CDATA section specifically tells the parser to treat the contents as non-XML data.

<alias
  enabled="y"
  match="^\s*foo\s*"
  regexp="y"
  >
  <send><![CDATA[
    if 1 < 2 then
      Note("I can use < and & just fine here!")
    end
  ]]></send>
  </alias>


You just have to be careful not to use "]]>" inside the CDATA section, because that's what ends it.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


58,698 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.