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


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 ➜ Simple GMCP plugin

Simple GMCP plugin

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


Pages: 1  2 3  4  5  

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #15 on Thu 02 Oct 2014 06:40 AM (UTC)
Message
The other issue is that a GetVariable "plugin variable" and a "script variable" are two different kinds of things. You're setting script variables in ShowHealth, but trying to access plugin variables in your alias.

Solution: In ShowHealth, do something like this for each variable instead:
SetVariable("hp", fulldata.Vitals.hp)

'Soludra' on Achaea

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

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #16 on Thu 02 Oct 2014 07:08 AM (UTC)

Amended on Thu 02 Oct 2014 07:10 AM (UTC) by Twisol

Message
Solara said:
Edit: Okay figured out the problem. I have to actually do SetVariable within the plugin for it to be called:
Prefer replying instead of editing if you have something new to add. I didn't see your edit because I had already posted a reply which wrapped onto the second page of the thread.

Solara said:
Now, can anyone help me pull the gmcp data for the Char.Team? It seems it's Char.Team.1 for first team member, Char.Team.2 for second team member, etc.
If you're using the GMCP_Demo.xml plugin, you'll need to edit OnPluginBroadcast to have it check for each individual message and call a new function instead of ShowHealth. If you're editing RoomName.plugin, you add a new GMCP.Listen() block for each message you're interested in, and you get the data as a parameter.

I'm not familiar with the Aardwolf GMCP plugin, and it uses opaque techniques (loadstring in particular) to bring arbitrary variables into scope, so it's hard to tell what OnPluginBroadcast is actually doing here.

'Soludra' on Achaea

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

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #17 on Thu 02 Oct 2014 07:49 AM (UTC)
Message
Solara said:

this is now my modified ShowHealth function within gmcp_demo:


It's best to post the complete plugin and the complete alias. You may be doing something wrong like not using the right plugin ID.

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.


Template:codetag To make your code more readable please use [code] tags as described here.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #18 on Thu 02 Oct 2014 07:50 AM (UTC)
Message
Twisol said:

Hi Solara (and Nick - long time no see!),


Hi Twisol!

How's the new client going?

- Nick Gammon

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

Posted by Solara   USA  (59 posts)  Bio
Date Reply #19 on Thu 02 Oct 2014 04:20 PM (UTC)

Amended on Thu 02 Oct 2014 09:34 PM (UTC) by Solara

Message
So this is my updated GMPC_Demo.xml to try to grab the Char.Team numbers.

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="GMCP_demo"
   author="Nick Gammon"
   id="b9171e77bc4ed6d2926eebdc"
   language="Lua"
   purpose="GMCP demonstration"
   date_written="2014-06-09"
   requires="4.73"
   version="1.0"
>
</plugin>

<!--  Script  -->

<script>
<![CDATA[

fulldata = {}

--=================================================================================
-- Called when plugin receives telnet data - main entry point for actually running
-- the plugin.
--=================================================================================
function OnPluginBroadcast (msg, id, name, text)

   -- Look for GMCP handler.
   if (id == '3e7dedbe37e44942dd46d264') then
      if (text == 'reload') then
         -- invalidate current data
         fulldata = {} 
         return
      end
     -- print ("GMCP packet = ", text)
      if (text == "Char.Vitals" or text == "Char.Team") then
         res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264","gmcpval","Char")

         luastmt = "gmcpdata = " .. gmcparg
         assert (loadstring (luastmt or "")) ()

         -- copy into fulldata
         for k, v in pairs (gmcpdata) do
           fulldata [k] = v
         end -- for
      
      if text == "Char.Vitals" then
        ShowHealth ()
      end -- if

      if text == "Char.Team" then
        ShowHealthTeam ()
      end -- if
      end
   end
end


function ShowHealth ()

  SetVariable ("HP_gmcp", fulldata.Vitals.hp)
  SetVariable ("Mana_gmcp", fulldata.Vitals.mana)
  SetVariable ("Fatigue_gmcp", fulldata.Vitals.fatigue)
  SetVariable ("Bleeding_gmcp", fulldata.Vitals.bleeding)

end -- ShowHealth

function ShowHealthTeam ()

  SetVariable ("HP_Team_1", fulldata.Team.hp)
  SetVariable ("Bleed_Team_1", fulldata.Team..blood)
  SetVariable ("Pos_Team_1", fulldata.Team..pos)

end -- ShowHealthTeam

]]>
</script>
</muclient>


I get this error when loading the plugin: [string "Plugin"]:51: bad argument #2 to 'SetVariable' (string expected, got nil)

This is the data I receive when gmpcdebug 1 is set:
Char.Vitals { "hp":100, "mana":100, "fatigue":0, "bleeding":0 }
Char.Team [{"blood":"0", "hp":"100", "leader":"0", "name":"Chiara", "pos":"0"}, {"blood":"0", "hp":"100", "leader":"1", "name":"Nicole", "pos":"1"}]


So I'm not sure how to modify the CallPlugin for Char.Team as it contains the same stats for different team members. Supposedly Char.Vitals and Char.Team should be pulled together since they both have Char as the top level. Any ideas?
Top

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #20 on Thu 02 Oct 2014 09:51 PM (UTC)
Message

  SetVariable ("Bleed_Team_1", fulldata.Team..blood)


What are the two dots?

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #21 on Thu 02 Oct 2014 09:52 PM (UTC)
Message
Try doing a tprint for debugging. It might become clearer:


require "tprint"
tprint (fulldata)

- Nick Gammon

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

Posted by Solara   USA  (59 posts)  Bio
Date Reply #22 on Thu 02 Oct 2014 10:14 PM (UTC)

Amended on Thu 02 Oct 2014 10:44 PM (UTC) by Solara

Message
Nick Gammon said:


  SetVariable ("Bleed_Team_1", fulldata.Team..blood)


What are the two dots?


Bad typing on my part, but despite correcting it I still get the same error code:

[string "Plugin"]:50: bad argument #2 to 'SetVariable' (string expected, got nil)

There's just no data in Char.Team.hp I guess. I know the data's there since gmcpdebug 1 shows it as listed above.

And this what I get when I enable tprint and have it print the fulldata.

"Team":
  1:
    "name"="Chiara"
    "pos"="0"
    "leader"="0"
    "hp"="100"
    "blood"="0"
  2:
    "name"="Nicole"
    "pos"="1"
    "leader"="1"
    "hp"="100"
    "blood"="0"
"Vitals":
  "fatigue"="0"
  "mana"="50"
  "hp"="100"
  "bleeding"="0"


How do I grab that nested data within Team.1 and Team.2 using the GMCP_Demo.xml code?
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #23 on Thu 02 Oct 2014 10:44 PM (UTC)
Message
Solara said:
Team.1 and Team.2

You might want to try calling them Team[1] and Team[2] instead. :)

'Soludra' on Achaea

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

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #24 on Thu 02 Oct 2014 10:51 PM (UTC)
Message
Nick Gammon said:
Hi Twisol!

How's the new client going?

Between work and a double-major at college, I haven't been able to spend any time on it for a long time now. It's in a usable state (full Telnet functionality, ANSI rendering with word wrapping, multi-line input), but the alias support is minimal, and there is no trigger functionality yet.

I should probably just upload it somewhere and let people try it. Unlike my original design, there's no need for a third-party proxy server: it runs entirely on your computer. The only requirement is that the MUD you're connecting to must have a WebSocket gateway, like the IRE games do.

'Soludra' on Achaea

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

Posted by Solara   USA  (59 posts)  Bio
Date Reply #25 on Thu 02 Oct 2014 10:52 PM (UTC)
Message
Twisol said:

Solara said:
Team.1 and Team.2

You might want to try calling them Team[1] and Team[2] instead. :)


Haha, awesome, that worked! Thanks for the help Nick and Twisol!
Top

Posted by Solara   USA  (59 posts)  Bio
Date Reply #26 on Fri 03 Oct 2014 09:24 PM (UTC)

Amended on Fri 03 Oct 2014 10:52 PM (UTC) by Solara

Message
Okay so on a similar note, I'm trying to set variables for up to 5 team members if the data is there.

I use this to set if if the Name for a team member # is not nil, but I get an error:

attempt to index field '?' (a nil value)
stack traceback:


If there are 2 team members, it seems to point to the line to set variables for Team[3] data as being nil.

Here's the portion of the plugin that errors out:
function ShowHealthTeam ()

if fulldata.Team[1].name ~= nil then
  SetVariable ("T1_Name", fulldata.Team[1].name)
  SetVariable ("T1_HP", fulldata.Team[1].hp)
  SetVariable ("T1_Blood", fulldata.Team[1].blood)
  SetVariable ("T1_Pos", fulldata.Team[1].pos)
end -- if

if fulldata.Team[2].name ~= nil then
  SetVariable ("T2_Name", fulldata.Team[2].name)
  SetVariable ("T2_HP", fulldata.Team[2].hp)
  SetVariable ("T2_Blood", fulldata.Team[2].blood)
  SetVariable ("T2_Pos", fulldata.Team[2].pos)

if fulldata.Team[3].name ~= nil then
  SetVariable ("T3_Name", fulldata.Team[3].name)
  SetVariable ("T3_HP", fulldata.Team[3].hp)
  SetVariable ("T3_Blood", fulldata.Team[3].blood)
  SetVariable ("T3_Pos", fulldata.Team[3].pos)
end -- if
end -- if


Do I have the syntax correct there?

I've tried these variations with the same error:

if not fulldata.Team[3].name then

if fulldata.Team[3].name ~= nil or "" then
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #27 on Fri 03 Oct 2014 10:36 PM (UTC)
Message
Try checking fulldata.Team[1] instead of fulldata.Team[1].name (for each team though, not just the 1st). If there is no 1st team, you'll basically have nil.name, which will cause your error.

'Soludra' on Achaea

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

Posted by Solara   USA  (59 posts)  Bio
Date Reply #28 on Fri 03 Oct 2014 11:49 PM (UTC)

Amended on Sat 04 Oct 2014 02:34 PM (UTC) by Solara

Message
Awesome, thanks again! That seems to have worked.

NOW just to play around and try to make for cleaner code, is it possible to do this? Instead of 8 instances of the same if/then groups, do a loop and replace the variable name with the number?

for x=1,8 do

if fulldata.Team&[x] ~= nil then
  SetVariable ("Ti_Name", fulldata.Team[x].name)
  SetVariable ("Ti_HP", fulldata.Team[x].hp)
  SetVariable ("Ti_Blood", fulldata.Team[x].blood)

  if fulldata.Team[x].pos == "0" then SetVariable ("Tx_Pos", "Front")
  else SetVariable ("Tx_Pos", "Back")
  end
end -- if
end


What I wrote there doesn't work and I suspect it's not replacing the numbers for i into the variables.
Top

Posted by Solara   USA  (59 posts)  Bio
Date Reply #29 on Fri 03 Oct 2014 11:54 PM (UTC)
Message
Oh and another question. The GMCP_Demo.xml plugin seems to maintain the table of data grabbed from the mud GMCP. So when a team member is no longer in the team, the plugin still seems to send old data?

I am almost sure that the MUD is not sending old data because gmcpdebug 1 or 2 shows the correct data.

Is there a command I can put into the plugin for it to erase/refresh the table of GMCP data each time it runs?
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.


144,343 views.

This is page 2, subject is 5 pages long:  [Previous page]  1  2 3  4  5  [Next page]

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

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]