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, confirm your email, resolve issues, 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 ➜ Wrong type of variable ! How to fix?

Wrong type of variable ! How to fix?

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


Posted by Winddancer   (26 posts)  Bio
Date Fri 28 Oct 2022 09:03 PM (UTC)
Message
I want to loot a given number of corpses.
For this I created the following alias:

  <alias
   script="loot"
   match="loot *"
   enabled="y"
   group="exploring"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>%1</send>
  </alias>

The script looks like this:

function loot(x)
	local i=1
        while i <= x
	do
		Send("get all from @i. corpse")
		i=i+1
	end -- do
end -- loot


I am getting the following scripting error:
[string "Script file"]:45: attempt to compare number with string
stack traceback:
[string "Script file"]:45: in function <[string "Script file"]:43>
Line 43 is the function name -> function loot(x)
Line 45 is the while loop -> while i <= x

How do I make sure that the passed variable, x, is interpreted as a number? I tried around with the tonumber() function but didn't get it to work.

Please help
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #1 on Fri 28 Oct 2022 09:33 PM (UTC)
Message
Use these instead


<aliases>
  <alias
   match="loot *"
   enabled="y"
   group="exploring"
   regexp="n"
   send_to="12"
   sequence="100"
  >
  <send>loot(%1)</send>
  </alias>
</aliases>



function loot(x)
    local i=1
    while i <= x do
        Send("get all from " .. i .. ".corpse")
        i=i+1
    end
end

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Winddancer   (26 posts)  Bio
Date Reply #2 on Fri 28 Oct 2022 09:55 PM (UTC)
Message
Thanks, this works as expected. :)
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.


5,321 views.

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

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