[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]  Buildship Runtime

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Buildship Runtime

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


Posted by Terry   USA  (87 posts)  [Biography] bio
Date Mon 01 Sep 2008 05:09 PM (UTC)  quote  ]

Amended on Mon 01 Sep 2008 05:20 PM (UTC) by Terry

Message
I made a plugin to automate building ships in LotJ.
<!--  Triggers  -->
<triggers>
  <trigger
   enabled="y"
   match="^(Where to begin\? It all looks so complex\.\.\.|You finish modifying the ship\.|You step away from (.*?)\, and realize you've done it all wrong\.\.\.)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Send("buildship " .. GetVariable("ship") .. " " .. GetVariable("part"))</send>
  </trigger>
  <trigger
   enabled="y"
   match="You don't have a component like that."
   send_to="12"
   sequence="100"
  >
  <send>Send("get 10 " .. GetVariable("part"))
Send("buildship " .. GetVariable("ship") .. " " .. GetVariable("part"))</send>
  </trigger>
  <trigger
   enabled="y"
   match="Your * doesnt need any more of that."
   send_to="12"
   sequence="100"
  >
  <send>if GetVariable("counter") == table.getn(parts) then
 SetVariable("counter", 0)
 SetVariable("part", "weapons")
 Send("buildship " .. GetVariable("ship") .. " weapons")
else
 SetVariable("counter", GetVariable("counter")+1)
 SetVariable("part", parts[GetVariable("counter")])
 Send("buildship " .. GetVariable("ship") .. " " .. GetVariable("part"))
end -- if</send>
  </trigger>
  <trigger
   enabled="y"
   match="You don't see a ship like that nearby to work on."
   sequence="100"
   send_to="12"
  >
  <send>Send("afk")
DeleteVariable("ship")
DeleteVariable("part")
DeleteVariable("counter")</send>
  </trigger>
</triggers>

<!--  Aliases  -->
<aliases>
  <alias
   match="sbship *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("ship", "%1")
SetVariable("counter", 0)
SetVariable("part", "weapons")
Send("buildship %1 weapons")</send>
  </alias>
</aliases>

<!--  Script  -->
<script>
<![CDATA[
parts = { }
 parts[0] = "weapons"
 parts[1] = "engines"
 parts[2] = "circuits"
 parts[3] = "hull"
]]>
</script>
However, when the MUD fired "Your Imperial-Class Star Destroyer doesnt need any more of that.", I got the following runtime:
Run-time error
Plugin: BuildShip (called from world: LotJ)
Immediate execution
[string "Trigger: "]:7: bad argument #2 to 'SetVariable' (string expected, got nil)
stack traceback:
[C]: in function 'SetVariable'
[string "Trigger: "]:7: in main chunk

I ran some checks, but they all turned out fine.
Note(GetPluginVariable("b30a643ea4eee52bb3d0c7dd", "part")) --> "weapons"
Note(GetPluginVariable("b30a643ea4eee52bb3d0c7dd", "counter")) --> 1
I don't see why it would think there was a nil value anywhere. Could someone help me?



Edit:
In a future release, would there be any chance you could do something like DeleteVariables({"var1", "var2", "var3"}) and DeletePluginVariables("b30a643ea4eee52bb3d0c7dd", {"var1", "var2", "var3"})? Also, this would be really nice: SetPluginVariable("b30a643ea4eee52bb3d0c7dd", "var1", "val"). The first two would just make it easier to do manipulate multiple variables at once. The last one would be send from the command box, and would be great for debugging.
[Go to top] top

Posted by Beale   (35 posts)  [Biography] bio
Date Reply #1 on Mon 01 Sep 2008 05:21 PM (UTC)  quote  ]
Message
I -believe- what's happening here is a slightly pesky type problem.

Try using this instead:

 SetVariable("part", parts[tonumber(GetVariable("counter"))])


As far as I know, MUSHClient variables are always converted to strings before they're stored, and aren't converted back when they're retrieved.
[Go to top] top

Posted by Terry   USA  (87 posts)  [Biography] bio
Date Reply #2 on Mon 01 Sep 2008 05:33 PM (UTC)  quote  ]
Message
Thanks, it works now! :) I really appreciate your help. But my other question still stands. Is there any chance that those functions could be added in a later release?
[Go to top] top

Posted by Beale   (35 posts)  [Biography] bio
Date Reply #3 on Mon 01 Sep 2008 06:11 PM (UTC)  quote  ]
Message
IANACoder in general, but when I'm debugging plugins and need the sort of access that you seem to want, I tend to just make an alias like:

<aliases>
  <alias
   name="DebugExec"
   match="plugin-exec *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>%1</send>
  </alias>
</aliases>


That way you can execute arbitrary code in the Plugin's namespace.
[Go to top] top

Posted by Nick Gammon   Australia  (18,797 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Tue 02 Sep 2008 12:52 AM (UTC)  quote  ]
Message
http://www.gammon.com.au/scripts/doc.php?function=DeleteVariable

- Nick Gammon

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

Posted by Terry   USA  (87 posts)  [Biography] bio
Date Reply #5 on Tue 02 Sep 2008 12:57 AM (UTC)  quote  ]
Message
That link sent me to DeleteVariable(), which isn't what I was suggesting. :) I was suggesting DeleteVariables(string *vars);. It would just let you delete multiple variables at once, instead of having to use the same function multiple times in a row.
[Go to top] top

Posted by Nick Gammon   Australia  (18,797 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Tue 02 Sep 2008 01:38 AM (UTC)  quote  ]
Message
Just write a tiny function to do that - I don't want to add things that could easily be replicated in scripting. Plus you would have the issue of the return codes - what if one can be deleted and one not? What would the return code be?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


1,836 views.

[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]