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
➜ 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 page
Posted by
| Errigour
USA (32 posts) 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:
[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")
| Top |
|
Posted by
| Fiendish
USA (2,533 posts) 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 | Top |
|
Posted by
| Errigour
USA (32 posts) 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) 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 | 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.
2,897 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top