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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  alias If statement check for argument

alias If statement check for argument

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


Posted by Errigour   USA  (32 posts)  [Biography] bio
Date Fri 19 Jan 2024 04:11 AM (UTC)

Amended on Fri 19 Jan 2024 04:46 AM (UTC) by Errigour

Message
I'm trying to make this simple program that casts a spell only if there is no argument passed. i cant figure it out it keeps saying args[1] is indexing a nil value.

if args[1] ~= nil then
  Send("cast 'invis'" .. args[1])
end
'
and while im asking might as well ask how to use the arg in Send to if i'm not right.

Here's the alias:

^sup( .*)?$



[string "Alias: "]:1: attempt to index global 'args' (a nil value)
stack traceback:
	[string "Alias: "]:1: in main chunk


Alright i think i just figured out a solution still if you want to add anything to this please do.

Send("cast 'invis'%1")
if "%1" == "" then
Send("cast 'detect invis'")
Send("cast 'protection evil'")
Send("cast 'detect evil'")
Send("cast 'detect magic'")
Send("cast 'detect alignment'")
end
Send("cast 'bless'%1")
Send("cast 'armor'%1")
Send("cast 'holy armor'%1")
Send("cast 'frenzy'%1")
[Go to top] top

Posted by Fiendish   USA  (2,525 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Fri 19 Jan 2024 05:04 AM (UTC)

Amended on Fri 19 Jan 2024 05:05 AM (UTC) by Fiendish

Message
Quote:
it keeps saying args[1] is indexing a nil value

This means that your "args" variable is nil, not a table like you expected. Where is args coming from?


Quote:
Send("cast 'invis'%1")

Yes, "%1" is indeed how you get that first (and only) capture from your alias. Glad you figured it out!

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Errigour   USA  (32 posts)  [Biography] bio
Date Reply #2 on Fri 19 Jan 2024 06:13 PM (UTC)
Message
oh i thought args[1] was a variable in mushclient. idk then i guess %1 is the only way to get the argument?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 19 Jan 2024 08:02 PM (UTC)
Message
It depends if you use "send to script" (in which case you use %1) or make a function in a script file, in which case you use args [1].

- 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,824 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]