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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ How make repeated commands compact?
How make repeated commands compact?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Orogan
(23 posts) Bio
|
Date
| Wed 05 Nov 2008 12:42 PM (UTC) |
Message
| Lets say I need to do:
a = "n1"
b = "n2"
Note ("sum = " ..(a + b))
And this a couple of times in a script with different n1 and n2.
Lazy as I am, I want put something in my script that lets
me type 'dosum (n1,n2)' and it would do the same as above.
How would i go about this?
The example above is just to explain what I want to do,
I'll try and work my way from there to what I need.
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Wed 05 Nov 2008 07:10 PM (UTC) |
Message
| You need to make your own function for this, eg.
function dosum (n1, n2)
local total -- local variable to hold results
total = n1 + n2
return total
end -- function
Or, more compactly in this case:
function dosum (n1, n2)
return n1 + n2
end -- function
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Orogan
(23 posts) Bio
|
Date
| Reply #2 on Wed 05 Nov 2008 09:07 PM (UTC) |
Message
| Did tought it was that simple :)
The scripts I took a look at made it seem more difficult to pas the values.
Thanks for the help.
| 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.
11,372 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top