[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Attempting to use wait to wait for a particular line and failing

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Attempting to use wait to wait for a particular line and failing
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Wed 04 Aug 2010 01:18 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Wed 04 Aug 2010 06:11 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Lilija   (9 posts)  [Biography] bio
Date Wed 04 Aug 2010 05:38 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Wed 04 Aug 2010 05:29 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Wed 04 Aug 2010 04:46 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Lilija   (9 posts)  [Biography] bio
Date Wed 04 Aug 2010 04:12 AM (UTC)  quote  ]

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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Tue 03 Aug 2010 09:16 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Lilija   (9 posts)  [Biography] bio
Date Tue 03 Aug 2010 08:30 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Worstje   Netherlands  (867 posts)  [Biography] bio
Date Wed 28 Jul 2010 07:54 AM (UTC)  quote  ]
Message
Opinions tend to differ, and different approaches have been used over the years by various people. All in all, I'd say you do what is best for you given your situation.

While you are still learning the basics, I'd recommend not to stick to a single plugin, and doing your scripting in its script tags as opposed to Sending to Script. That way, you won't run into extra difficulty of loading other files, and be able to keep it quite contained, while at the same time getting more insight into how MUSHclient works on the inside.

For example, you can use the Plugin Wizard to create a really basic plugin if you want, and look at the file it generates, and from then on edit that file rather than work your way through the crappy MUSHclient interface for editing stuff. It takes a bit of getting used to, but once you get past the hurdle you won't want to do it any differently. :)

Additionally, you can look at the plugins supplied with MUSHclient, or ask other people on these forums for example plugins they have written.
[Go to top] top

Posted by Lilija   (9 posts)  [Biography] bio
Date Wed 28 Jul 2010 07:49 AM (UTC)  quote  ]
Message
And, since I still can't seem to grasp what seem like they should be basic things.

Is there some sort of tut on the forums that discusses what belongs in what file type? Ie I imagine most code/logic belongs in .lua files, whereas aliases/triggers/variables go in .xml files. If this is the case, if I define a function in a .lua file, am I then able to use it within an alias from a .xml file, and what's a general syntax to do so? I played with this for half an hour, and can't seem to figure it out.

My current file that I was using before I decided to make it a bit more modular was a .lua file that I loaded in using File, Import. I'd like to split the functionality of what I'm doing across multiple files to keep my code cleaner.

I apologize if this makes little since, since it's late where I am. If you need a better explanation, I'll provide one tomorrow.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Wed 28 Jul 2010 06:44 AM (UTC)  quote  ]
Message
See:

http://www.gammon.com.au/scripts/doc.php?lua=require

In particular:

http://www.gammon.com.au/scripts/doc.php?lua=package.path

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Wed 28 Jul 2010 06:42 AM (UTC)  quote  ]
Message
require("subfolder.yourscript")


That will look for lua/subfolder/yourscript.lua (among other paths).

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Lilija   (9 posts)  [Biography] bio
Date Wed 28 Jul 2010 06:34 AM (UTC)  quote  ]

Amended on Wed 28 Jul 2010 06:35 AM (UTC) by Lilija

Message
I'm a moron. Realized what I was doing wrong, and I can just make the user stick it in the lua folder I suppose. Any way to tell it to look inside a folder inside the lua folder? Or will it do that automatically?
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Wed 28 Jul 2010 06:01 AM (UTC)  quote  ]
Message
Can you post the message? Require normally lists a whole heap of places it looks if it fails. Is your file in one of those?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Lilija   (9 posts)  [Biography] bio
Date Wed 28 Jul 2010 05:44 AM (UTC)  quote  ]
Message
I've looked around a few places on the forums as well as the site, and haven't been successful in locating the information I'm looking for. I'd like to modularize my script into a few different files. When I try to import them in (via require, as in: require "myfile") it's unable to find them. Is there something specific I need to set to do this? Or do I need to locate the files in a specific folder?

I feel like an idiot not being able to figure it out. So thanks for bearing with me.
[Go to top] 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.


5,243 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]