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

Gammon Forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Plugins, Info-bars and variables
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Plugins, Info-bars and variables

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


Posted by Rodriguez   (22 posts)  [Biography] bio
Date Sun 20 Sep 2009 02:49 PM (UTC)

Amended on Sun 20 Sep 2009 02:52 PM (UTC) by Rodriguez

Message
I wrote a plugin to keep track of my affects but have some difficulties with a timer to check my variables:


<!--  Timers  -->

<timers>
  <timer enabled="y" second="1.00" send_to="12">
    <send>
	InfoBackground ("black")
	InfoClear ()
	if string.find(GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1'),"^=") == nil then
		InfoColour("green")
		Info (GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1'))
	else
		InfoColour("red")
		Info (GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1'))
	end
    </send>

  </timer>
</timers>


If the variable named "prio1" starts with a = (e.g "= fly down =")then it should colour it green and otherwise red.

Is there maybe a problem with the "if"?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Mon 21 Sep 2009 01:31 AM (UTC)
Message
You have it backwards. The test for "== nil" will be true if the condition does *not* match.

- Nick Gammon

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

Posted by Rodriguez   (22 posts)  [Biography] bio
Date Reply #2 on Wed 23 Sep 2009 05:22 PM (UTC)
Message
Ah thats just a typo in my explanation, the problem was somewhere else (the "send to" part of my triggers were wrong).

Thanks anyway :)
[Go to top] top

Posted by Rodriguez   (22 posts)  [Biography] bio
Date Reply #3 on Sat 10 Oct 2009 06:24 PM (UTC)
Message
I decided to redo my plugin to make it easier to adopt to other characters. So I tried to move the trigger conditions into variables but somehow it stoped working. I didnt get any compile errors so I guess its a problem with the matching text or the variables.



  <variable name="prio1spell">co 'armor of thorns'</variable>
  <variable name="prio1downmessage">Your armor of thorns disappears.</variable>
  <variable name="prio1upmessage">Thorns sprout from your skin as you undergo metamorphosis.</variable>
  <variable name="prio1do"> =armor= </variable>
  <variable name="prio1up">  armor  </variable>
  <variable name="prio1current"> =armor= </variable>



  <trigger
   enabled="y"
   match="GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1upmessage')"
   name="p1up"
   sequence="100"
   send_to="12"
  >
   <send>
    SetVariable ("prio1current", GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1up'))
   </send>
  </trigger>


Any idea what went wrong?
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #4 on Sat 10 Oct 2009 07:30 PM (UTC)

Amended on Sat 10 Oct 2009 07:31 PM (UTC) by Twisol

Message
match="GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1upmessage')"


What, exactly, are you attempting to match?

'Soludra' on Achaea

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 10 Oct 2009 08:35 PM (UTC)
Message
Quote:

match="GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1upmessage')"


That won't work. You can't put a script function in as the match string. That would literally match what you typed there.

If the plugin is the one you are currently running (ie. you are not trying to get a variable from a different plugin), all you have to do is:


 match="@prio1upmessage"


... and check "expand variables".

- Nick Gammon

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

Posted by Rodriguez   (22 posts)  [Biography] bio
Date Reply #6 on Sat 10 Oct 2009 09:00 PM (UTC)
Message
Twisol said:

match="GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1upmessage')"


What, exactly, are you attempting to match?


The string:
"Thorns sprout from your skin as you undergo metamorphosis."
I put into the variable named 'prio1upmessage'


Nick Gammon said:

If the plugin is the one you are currently running (ie. you are not trying to get a variable from a different plugin), all you have to do is:


 match="@prio1upmessage"


... and check "expand variables".



Thanks a lot, will give it a try. :)
[Go to top] top

Posted by Rodriguez   (22 posts)  [Biography] bio
Date Reply #7 on Tue 24 Nov 2009 04:53 PM (UTC)
Message
I decided to redo my plugin to use miniwindows instead of the infobar but somehow I got some trigger problems again...
I trimmed the code down to one spell to make it less verbose.


The triggers on the prio1up and prio1down triggers work it seems but the triggers on the affects command:


You are affected by:
Spell: 'desensitize' for a short time.
Spell: 'fly' for a very short time.
Spell: 'ocular enhancement' for a short time.
Spell: 'ocular enhancement' for a short time.
Spell: 'ocular enhancement' for a short time.
Spell: 'invis' for a medium time.


Seem not to work at all.
Neither the trigger on "You are affected by" nor the prio1affectregex I used.




<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, February 19, 2008, 2:31 PM -->
<!-- MuClient version 4.14 -->

<!-- Plugin "Spellup_Script" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Spellup_Script"
   author="Rodriguez"
   id="f9e3698e93e4ac3786236acf"
   language="Lua"
   purpose="Keep track of affects"
   date_written="2008-02-19 14:26:09"
   requires="3.23"
   version="1.0"
   >
<description trim="y">
<![CDATA[
This plugin will keep track of your affects.
]]>
</description>

</plugin>




<!--  Variables  -->

<variables>
  <variable name="prio1spell">c 'desensitize'</variable>
  <variable name="prio1downmessage">You feel pain normally once again.</variable>
  <variable name="prio1upmessage">You will the sensation of pain to retreat from your flesh.</variable>
  <variable name="prio1affectregex">Spell\: \'desensitize\'</variable>
  <variable name="prio1do"> =desensitize= </variable>
  <variable name="prio1up">  desensitize  </variable>
  <variable name="prio1current"> =desensitize= </variable>

</variables>






<!--  Triggers  -->

<triggers>

  <trigger
   enabled="y"
   match="You are affected by"
   name="clearstat"
   sequence="100"
   send_to="12"
  >
   <send>
    SetVariable ("prio1current", GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1do'))
   </send>
  </trigger>

  
  <trigger
   custom_colour="7"
   enabled="y"
   match="@prio1downmessage"
   expand_variables="y"
   name="p1down"
   sequence="100"
   send_to="12"
  >
   <send>
    SetVariable ("prio1current", GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1do'))
   </send>
  </trigger>
  
  <trigger
   enabled="y"
   match="@prio1upmessage"
   expand_variables="y"
   name="p1up"
   sequence="100"
   send_to="12"
  >
   <send>
    SetVariable ("prio1current", GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1up'))
   </send>
  </trigger>

  <trigger
   enabled="y"
   match="@prio1affectregex"
   regexp="y"
   expand_variables="y"
   name="p1stat"
   sequence="100"
   send_to="12"
  >
   <send>
    SetVariable ("prio1current", GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1up'))
   </send>
  </trigger>
 

</triggers>


<!--  Timers  -->

<timers>
  <timer enabled="y" second="1.00" send_to="12">
  <send>

require "var"

-- make window if required
if not setup_affects_window then

  affects_win = GetPluginID () .. ":affects" -- get a unique name
  WindowCreate (affects_win , 0, 0, 250, 310, 6, 1, ColourNameToRGB("black"))  -- create window

  WindowFont (affects_win, "f", "FixedSys", 9) -- define font
  target_font_height  = WindowFontInfo (affects_win , "f", 1)  
  setup_affects_window = true

end -- if first time

-- blank existing window contents

WindowRectOp (affects_win, 2, 0, 0, 0, 0, WindowInfo (affects_win, 9))

-- framing rectangle
WindowRectOp (affects_win, 5, 0, 0, 0, 0, 5, 15)

-- variables for text position (the top updates as we move down)
local left = 5
local top = 5

-- current queue
WindowText (affects_win, "f", "Placeholder: " .. (var.target or "none"), 
            left, top, 0, 0, ColourNameToRGB("white"))
top = top + target_font_height + 10



-- Current Affects
if string.find(GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1current'),"=") == nil then
	WindowText (affects_win, "f", GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1current'), 
            left, top, 0, 0, ColourNameToRGB("green"))
else
	WindowText (affects_win, "f", GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1current'), 
            left, top, 0, 0, ColourNameToRGB("red"))
end            
top = top + target_font_height  





-- make visible, or refresh if already visible
WindowShow (affects_win ,  true)  

</send>

  </timer>
</timers>






<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="Spellup:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
function OnHelp (sName, sLine, wildcards)
  World.Note (World.GetPluginInfo (World.GetPluginID, 3))
end
]]>
</script> 

</muclient>




Any ideas or is there a way to debug plugins? The regex seem to work but some bug must be in there. :/
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Tue 24 Nov 2009 08:01 PM (UTC)
Message
Quote:

match="You are affected by"

...

You are affected by:


They aren't the same. You need to match on "You are affected by:" and maybe there is a trailing space. You need to carefully check trigger matches.

Try turning on Game menu -> Trace to see what is matching.




This is too complex and confusing:


SetVariable ("prio1current", GetPluginVariable ('f9e3698e93e4ac3786236acf', 'prio1do'))


This plugin is ID "f9e3698e93e4ac3786236acf", right?

So just write:


SetVariable ("prio1current", GetVariable ('prio1do'))



- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Tue 24 Nov 2009 08:32 PM (UTC)
Message
As for the other triggers, I overlooked something in my earlier answer. You can indeed do something like this:


match="@prio1upmessage"


However, MUSHclient helpfully "escapes" any special characters inside the match text so the regular expression matcher doesn't get confused. However if you deliberately put a regular expression there, you need to add a "!" like this:


match="@!prio1upmessage"


When I do that, and with Trace on, I see this:


You are affected by:
Spell: 'desensitize' for a short time.
TRACE: Matched trigger p1stat
Spell: 'fly' for a very short time.


- Nick Gammon

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

Posted by Rodriguez   (22 posts)  [Biography] bio
Date Reply #10 on Wed 25 Nov 2009 04:23 PM (UTC)
Message
Wow, that fixed all problems! :D
Also found another typo thanks to trace, will remember using that next time.

Thanks a lot!
[Go to top] top

Posted by Rodriguez   (22 posts)  [Biography] bio
Date Reply #11 on Sat 05 Dec 2009 10:06 AM (UTC)
Message
It never ends...

I tried to add a scrip function to my plugin that creates a list of missing spells according to priority and casts the highest one on the press of a button.



<!--   Script  -->

<script>
<![CDATA[
function OnHelp (sName, sLine, wildcards)
  World.Note (World.GetPluginInfo (World.GetPluginID, 3))
end



function CastAll ()
  ArrayCreate "spells"
  ArrayClear "spells"
  
  if string.find(GetVariable ('prio1current'),"=") ~= nil then
	ArraySet ("spells", 1, GetVariable ('prio1spell'))
  end            


  if string.find(GetVariable ('prio2current'),"=") ~= nil then
	ArraySet ("spells", 2, GetVariable ('prio2spell'))
  end            


  if string.find(GetVariable ('prio3current'),"=") ~= nil then
	ArraySet ("spells", 3, GetVariable ('prio3spell'))
  end            
  
  CastFirst(spells)

end

function CastFirst (spells)
	if (ArrayGetFirstKey ("spells") ~= nil) then
		return ArrayGetFirstKey ("spells"))
	else
		return ""
	end	
end		



]]>
</script> 




But for some reason I get an error message when I try to load the script looking like this:


Compile error
Plugin: Spellup_Script (called from world: Carrion Fields)
Immediate execution
[string "Plugin"]:72: 'end' expected (to close 'if' at line 71) near ')'
Error context in script:
  68 : end
  69 : 
  70 : function CastFirst (spells)
  71 :  if (ArrayGetFirstKey ("spells") ~= nil) then
  72*:   return ArrayGetFirstKey ("spells"))
  73 :  else
  74 :   return ""
  75 :  end 
  76 : end



I was checking Lua tutorials and the like but
if (something) then
something
else
something
end

should be correct syntax...

Is it a problem that I decided to put it in the existing <script> tag?
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #12 on Sat 05 Dec 2009 04:12 PM (UTC)
Message

function CastFirst (spells)
	if (ArrayGetFirstKey ("spells") ~= nil) then
		return ArrayGetFirstKey ("spells"))


You have an extra close paren on the return line.
[Go to top] top

Posted by Rodriguez   (22 posts)  [Biography] bio
Date Reply #13 on Sat 05 Dec 2009 05:32 PM (UTC)
Message
WillFa said:

You have an extra close paren on the return line.


Embarrassing... :-(
[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.


8,975 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]