Buildship Runtime

Posted by Terry on Mon 01 Sep 2008 05:09 PM — 7 posts, 29,806 views.

USA #0
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.
Amended on Mon 01 Sep 2008 05:20 PM by Terry
#1
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.
USA #2
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?
#3
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.
Australia Forum Administrator #4
http://www.gammon.com.au/scripts/doc.php?function=DeleteVariable
USA #5
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.
Australia Forum Administrator #6
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?