Register forum user name Search FAQ

Gammon Forum

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 ➜ General ➜ Contents of variable from within a script

Contents of variable from within a script

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


Posted by Mazarin   (14 posts)  Bio
Date Thu 29 Jul 2010 07:31 AM (UTC)

Amended on Thu 29 Jul 2010 09:21 AM (UTC) by Mazarin

Message
I want to access the contents of a variable from a script-text.

How is that done?

I can't write "Send ("wield @weapon")" - which would not, as desired, result in wield (dagger, sword or whip or whatever the contents of the variable "weapon" is).

Thank you.

// Mazarin
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 30 Jul 2010 02:02 AM (UTC)
Message
Is this inside an alias "send to script"? Or inside a script file?

In either case, you can do this:


Send ("wield " .. GetVariable ("weapon"))


This is getting the MUSHclient variable "weapon", not the script variable "weapon".

Template:scripting Scripting tutorial

There is extensive information about scripting in MUSHclient at http://mushclient.com/scripting. This includes screen shots and examples.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Mazarin   (14 posts)  Bio
Date Reply #2 on Thu 19 Aug 2010 10:07 AM (UTC)
Message
But, however the command

Send ("wield " GetVariable("weapon"))

will not work but gives an error message (msg = [string "Trigger: "]:1: ')' expected near 'GetVariable'). I think that what is needed is some type of concatenation of the string "wield" with the contents of the variable "weapon", but how to do that is more than i know.

Anybody, help, please?

//Mazarin







Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 19 Aug 2010 12:52 PM (UTC)
Message
Better look up the Lua reference, huh?

But concatenation is easy enough:


Send ("wield " .. GetVariable("weapon"))


In fact, didn't I say exactly that earlier up?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Mazarin   (14 posts)  Bio
Date Reply #4 on Sat 11 Sep 2010 10:32 PM (UTC)

Amended on Sat 11 Sep 2010 10:36 PM (UTC) by Mazarin

Message
Hi, I'm still building my combat aliases.

Now, how can I address the contents of the string in the variable "%1" - is it a variable - from within a script alias. I would like to write to the mud the command "cast missile mule", "cast chill horse" or "cast heal Mazarin" etc. From within a command alias I would use "cast MySpell %1" (when the variable MySpell has the contents of "missile", "chill" and "heal" respectively) and %1 is entered from the keyboard? Howto do this from within a scriptalias?

The commandline - I'm trying to send the command "kick", which is the content of the variable "attackskill" - in

Send ("" .. GetVariable("attackskill"))

works (sends "kick or whatever is in "attackskill")to the MUD but the commandline

Send GetVariable("attackskill")

does not, but gives error message "[string "Alias: "]:1: '=' expected near 'GetVariable'"? Seems odd to me?

Any help. Thank you.

//Mazarin
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #5 on Sun 12 Sep 2010 12:46 AM (UTC)

Amended on Sun 12 Sep 2010 12:47 AM (UTC) by Twisol

Message
Mazarin said:
The commandline - I'm trying to send the command "kick", which is the content of the variable "attackskill" - in

Send ("" .. GetVariable("attackskill"))

works (sends "kick or whatever is in "attackskill")to the MUD but the commandline

Send GetVariable("attackskill")

does not, but gives error message "[string "Alias: "]:1: '=' expected near 'GetVariable'"? Seems odd to me?


The parentheses are required (minus a couple exceptions). In Lua, a variable (i.e. Send) followed by parentheses is interpreted as a function call. Your second example doesn't have this syntactic cue, so Lua doesn't understand what you're trying to do.

Send(GetVariable("attackskill"))

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Mazarin   (14 posts)  Bio
Date Reply #6 on Sun 12 Sep 2010 07:49 AM (UTC)

Amended on Sun 12 Sep 2010 08:17 PM (UTC) by Mazarin

Message
Twisol said:
The parentheses are required (minus a couple exceptions). In Lua, a variable (i.e. Send) followed by parentheses is interpreted as a function call. Your second example doesn't have this syntactic cue, so Lua doesn't understand what you're trying to do.

Send(GetVariable("attackskill"))





This is quite clear. The sentence to to be sent is to be imbedded in parenthecis while the quotation marks have a different meaning. This was not clear to me. Thank you for the advice.

I noticed i had made a mistake in my previous post when i wrote that I wish to give the same command as in a within-alias script of "cast MySpell %1". I would of course like to send the command "cast @MySpell %1", that is send to the mud a command like "cast kick mule" or "cast heal Mazarin" or any similar command, ie. the spellname followed by my input.

Now my question is: how do I accomplish this? How do i write a command containing as well the contents of a variable as the input from the keyboard to the MUD?

Thank you.

//Mazarin


Nevermind. I found the solution. Thanks anyway.

//M.
Top

Posted by Eloni   (28 posts)  Bio
Date Reply #7 on Tue 07 Dec 2010 02:57 PM (UTC)

Amended on Tue 07 Dec 2010 03:07 PM (UTC) by Eloni

Message
So how would you do the same thing, but with the script variable "weapon"? Or what command is needed to use an array value? Would arrays be any different?

I tried to use the above on my variable, which contains an array, and I received a nil value. I guess this is expected since it only works for MushClient variables.

An example-- if I'm trying to (hypothetically):




useThisSpell = arrayOfDifferentSpells[math.random(15)]


Send ("cast " .. GetVariable("useThisSpell"))




Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #8 on Wed 08 Dec 2010 12:50 AM (UTC)

Amended on Wed 08 Dec 2010 08:20 AM (UTC) by Nick Gammon

Message
Template:post=10794 Please see the forum thread: http://gammon.com.au/forum/?id=10794.


This would be a Lua variable - you can serialize Lua variables into MUSHclient variables for saving over sessions.

Template:post=4960 Please see the forum thread: http://gammon.com.au/forum/?id=4960.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Eloni   (28 posts)  Bio
Date Reply #9 on Thu 09 Dec 2010 03:08 AM (UTC)
Message
Thanks! I'm going to give it a shot.
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.


29,200 views.

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

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.