alias If statement check for argument

Posted by Errigour on Fri 19 Jan 2024 04:11 AM — 4 posts, 10,031 views.

USA #0
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")
Amended on Fri 19 Jan 2024 04:46 AM by Errigour
USA Global Moderator #1
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!
Amended on Fri 19 Jan 2024 05:05 AM by Fiendish
USA #2
oh i thought args[1] was a variable in mushclient. idk then i guess %1 is the only way to get the argument?
Australia Forum Administrator #3
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].