trying to set up a script and ran into an error

Posted by Dragonlord on Fri 25 Mar 2016 06:04 PM — 6 posts, 20,802 views.

#0

<aliases>
  <alias
   match="players_equipment"
   enabled="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>PC_Equipment = "an eye of a Kraken|a ring of wizardry|the ring of the serpent|the Overlord's necklace of protection|a holy symbol of Ithrilis|a set of overlord armor|the leggings of an elder dragon|a pair of golden-spurred boots|the lieutenant's gauntlets|a pair of green dragonscale sleeves|a battered iron shield|Yourban's soul|a spectral aura|the belt of the master craftsman|a magical belt pouch|a bracelet set with white moonstones|a bracelet of the elements|an Eldmarian Slayer"

for PC_Equipment in string.gmatch (PC_Equipments, "%a+") do
  Send ("remove all\.", PC_Equipment)
  Send ("wear 'a pair of brass spectacles'")
  send ("wear ", PC_Equipment)
end -- for</send>
  </alias>
</aliases>



The error is those:


Run-time error
World: Materia Magica GMCP
Immediate execution
[string "Alias: "]:3: bad argument #1 to 'gmatch' (string expected, got nil)
stack traceback:
        [C]: in function 'gmatch'
        [string "Alias: "]:3: in main chunk
Amended on Fri 25 Mar 2016 08:40 PM by Nick Gammon
Australia Forum Administrator #1
You have a couple of typos:


PC_Equipment = "an eye of a Kraken ...


That should be:


PC_Equipments = "an eye of a Kraken ...



Also the final "send" should be "Send".
#2
thank you it helped. I added a wait.time script to it


<aliases>
  <alias
   match="players_equipment"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>PC_Equipments = "an eye of a Kraken|a ring of wizardry|the ring of the serpent|the Overlord's necklace of protection|a holy symbol of Ithrilis|a set of overlord armor|the leggings of an elder dragon|a pair of golden-spurred boots|the lieutenant's gauntlets|a pair of green dragonscale sleeves|a battered iron shield|Yourban's soul|a spectral aura|the belt of the master craftsman|a magical belt pouch|a bracelet set with white moonstones|a bracelet of the elements|an Eldmarian Slayer"

require "wait"
wait.make (function ()
for PC_Equipment in string.gmatch (PC_Equipments, "%a+") do
  Send ("remove all.", PC_Equipment)
  wait.time(1)
  Send ("wear 'a pair of brass spectacles'")
  wait.time(1)
  Send ("wear ", PC_Equipment)
end -- forend -- for
end) -- function</send>
  </alias>
</aliases>


for some reason it got caught in a endless loop. any idea what i did to cause it
Amended on Sat 26 Mar 2016 05:57 AM by Nick Gammon
Australia Forum Administrator #3
Your splitting up of the string is a bit strange anyway. This seemed to work for me:


<aliases>
  <alias
   match="players_equipment"
   enabled="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>

PC_Equipments = "an eye of a Kraken|a ring of wizardry|the ring of the serpent|the Overlord's necklace of protection|a holy symbol of Ithrilis|a set of overlord armor|the leggings of an elder dragon|a pair of golden-spurred boots|the lieutenant's gauntlets|a pair of green dragonscale sleeves|a battered iron shield|Yourban's soul|a spectral aura|the belt of the master craftsman|a magical belt pouch|a bracelet set with white moonstones|a bracelet of the elements|an Eldmarian Slayer"

require "wait"
wait.make (function ()

Send ("remove all")

for k, v in ipairs (utils.split (PC_Equipments, "|")) do
  Send ("wear ", v)
  wait.time (1)
end -- for

end) -- function

</send>
  </alias>
</aliases>

Australia Forum Administrator #4
A simpler approach is to not use a lengthy string in the first place. Like this:


<aliases>
  <alias
   match="players_equipment"
   enabled="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>

PC_Equipments = 
  {
  "an eye of a Kraken",
  "a ring of wizardry",
  "the ring of the serpent",
  "the Overlord's necklace of protection",
  "a holy symbol of Ithrilis",
  "a set of overlord armor",
  "the leggings of an elder dragon",
  "a pair of golden-spurred boots",
  "the lieutenant's gauntlets",
  "a pair of green dragonscale sleeves",
  "a battered iron shield",
  "Yourban's soul",
  "a spectral aura",
  "the belt of the master craftsman",
  "a magical belt pouch",
  "a bracelet set with white moonstones",
  "a bracelet of the elements",
  "an Eldmarian Slayer",
  }

require "wait"
wait.make (function ()

Send ("remove all")

for k, v in ipairs (PC_Equipments) do
  Send ("wear ", v)
  wait.time (1)
end -- for

end) -- function
</send>
  </alias>
</aliases>

#5
Thank you that did it