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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  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] Refresh page


Posted by Winddancer   (26 posts)  [Biography] 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
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] 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
[Go to top] top

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


3,862 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] 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]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]