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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Sending a command to a specific world

Sending a command to a specific world

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


Posted by Sev   (8 posts)  [Biography] bio
Date Thu 12 Apr 2007 09:05 AM (UTC)
Message
Hi,

I would like to be able to send a command to another world by means of an allias, but am not sure how I may do so.

So for example, I have 2 worlds running (denoted W1 and W2), and while active on W1, wish to use the alias "r" (defined in W1) that would cause the command "rescue sev" to execute on W2.

Your help is greatly appreciated.

Thanks
Sev
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 12 Apr 2007 09:46 AM (UTC)
Message
See the examples on this page:

http://www.gammon.com.au/scripts/doc.php?function=GetWorld

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Sev   (8 posts)  [Biography] bio
Date Reply #2 on Thu 12 Apr 2007 10:37 AM (UTC)
Message
Just wondering ... do GetWorldIdList() and GetWorldList() always return a list of world in the same order (assuming that there are no changed to the worlds list between the execution of the 2 functions)?

And are world IDs static such that I can hardcode World IDs into my scripts?

And what (in your opinion) would be the best way to synchronise the world information so that when I use alias "r", the "rescue sev" command is always applied to the correct world?
[Go to top] top

Posted by Onoitsu2   USA  (248 posts)  [Biography] bio
Date Reply #3 on Thu 12 Apr 2007 12:25 PM (UTC)
Message
world ID's are static as you stated, just open a world file in something like notepad and locate near the top the id=" line.

The actual REFERENCE to said world ID is what changes, as its location in memory is different every opening of it.

you will have to do a 'GetWorldByID(ID HERE)' call and set the returned value to a variable, that you use to send the command to...
i.e. world2=GetWorldByID("XXXXXX")
world2.execute "rescue sev"

I used execute, as you stated that you needed it to "execute" not send to mud.

Hope that helps you some :)

Laterzzz,
Onoitsu2
[Go to top] top

Posted by Sev   (8 posts)  [Biography] bio
Date Reply #4 on Thu 12 Apr 2007 07:19 PM (UTC)

Amended on Thu 12 Apr 2007 07:29 PM (UTC) by Sev

Message
What if I want to run a script (in W2) instead of "rescue sev" (e.g., a script that can also be called by an alias in W2: rescue_sev(name, line, wildcards))?

EDIT: atm, I'm using ...

sub w2_do(name, line, wildcards)
dim w2
set w2 = world.getworld("W2_NAME")
if w2 is nothing then
world.note "w2 is not open."
else
if line = "r" then
world.note "w2 -> r"
w2.note "w1 <- r"
w2.execute "/rescue_sev nil, nil, nil"
end if
end if
end sub

... which seems to work ... but I'm wondering if there is a less-dodgy way to do this.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 12 Apr 2007 09:46 PM (UTC)
Message
Quote:

... do GetWorldIdList() and GetWorldList() always return a list of world in the same order (assuming that there are no changed to the worlds list between the execution of the 2 functions)?


Yes, the return the worlds found in the internal world list, the same list that is used to general world numbers (world 1, world 2 etc.).

Quote:

And are world IDs static such that I can hardcode World IDs into my scripts?


Just to clarify, GetWorldIdList was added because there is no restriction on world names, you can have 10 worlds all called "untitled". However MUSHclient refuses to open two (or more) worlds which have the same ID string.

So, using GetWorldIdList is safer than GetWorldList.

Inside the world file, if you open it with a text editor, you will see something like this:


<muclient>
<world
   muclient_version="3.85"
   world_file_version="15"
   date_saved="2007-04-11 16:48:24"

   auto_say_override_prefix="-"
   auto_say_string="say "
   chat_name="Name-not-set"
   command_stack_character=";"
   id="f0b5158d0dc7909191f86c7e"
   input_font_name="FixedSys"


The bold line is the world ID. If you simply copy and paste a world file you will get two with the same ID. You need to Edit menu -> Generate Unique ID to get a new one.

Once a world has a fixed ID you don't need to use GetWorldIdList at all, simply specify the unique ID in GetWorldById.

Quote:

What if I want to run a script (in W2) instead of "rescue sev" (e.g., a script that can also be called by an alias in W2: rescue_sev(name, line, wildcards))?


I'm not sure I understand the question here. If you are "in" W2, then you don't need to get its own world ID.

Quote:

I'm wondering if there is a less-dodgy way to do this.


Your approach seems OK, apart from maybe the test for "r" in the middle - is that necessary?

To make it safer, get the world ID instead of the name:


set w2 = GetWorldById ("8524c85ef23a9c1bc5e53924")


Your ID will be different of course. To find it you can type:


/Note GetWorldID


I have been experimenting with being able to call the function directly (and not use world.Execute) but it seems that this won't work because world 1 doesn't know about extra scripts recently added to world 2.

A slightly safer method would be to use an alias in world 2, not a script call. You would still use Execute, but make up an alias which does what you want. The technique of using a script call (like: /rescue_sev nil, nil, nil) relies upon the correct script prefix ("/") being set up, and the function call arguments begin setup correctly.

In other words, something like this:


w2.Execute "My_Rescue_Alias"


If you need to pass down something (like who to rescue) it could be an argument the alias, eg.


w2.Execute "My_Rescue_Alias " & line

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Sev   (8 posts)  [Biography] bio
Date Reply #6 on Fri 13 Apr 2007 05:31 AM (UTC)
Message
Hi Nick,

Thanks for the rely, only 1 other thing remains unclear to me; when you say that "The technique of using a script call (like: /rescue_sev nil, nil, nil) relies upon the correct script prefix ("/") being set up, and the function call arguments begin setup correctly.", how exactly does one set up the arguments correctly?

More specifically, when I have a wildcard being passed from the the alias in W1, which is then passed to the script in W1, that atempts to call the script in W2, how should that wildcard be sent to W2?

Essentially, I can only get the direct calls to W2's scripts to work when there are no parameters being passed on (i.e., nil, nil, nil). However, when I wish to pass on more than that, I don't know to make it work - "how exactly does one set up the arguments correctly?"

Thanks
Sev
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Fri 13 Apr 2007 06:01 AM (UTC)
Message
Well, arguments to the alias in W1 are in the wildcards array.

So, you can pull them out like this:


w2.execute "/rescue_sev """ & wildcards (1) & "", nil, nil"


The use of the quotes is a bit confusing because you have to double them, as the line itself is quoted.

Say your alias is: match: r *

So you might type: r nick

That makes "nick" wildcard 1. Thus, when you do the execute, it now calls W2 with:


/rescue_sev "nick", nil, nil


Your use of nil is confusing too, because nil is really a Lua concept.

I'm not sure why you are calling rescue_sev with 3 arguments. Aliases and triggers, when called by MUSHclient, are passed 3 arguments, but there is no reason why your own functions have to have that many.

I think it would be simpler to make an alias in W2 (called rescue_sev if you like), and then you can pass it arguments. Eg. in W2:

Match: rescue_sev *

Now W1 can do this: ws:Execute "rescue_sev blah"

This passes "blah" as wildcard 1 to rescue_sev in W2.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Sev   (8 posts)  [Biography] bio
Date Reply #8 on Fri 13 Apr 2007 07:09 AM (UTC)
Message
Thanks again Nick,

Let me try to respond to some of your questions to see if you agree with what I am attempting to do.

(1) From your second post (third was most recent) - "Your approach seems OK, apart from maybe the test for "r" in the middle - is that necessary?"

Esentially, I intend to have one common script (sub W2_do) in W1 that: (i) is called via several aliases in W1, and (ii) either "executes" some script in W2 or "sends" specific strings to W2. I do this as I wish to control W2 via W1. I have W2_do as a large script as opposed to many small functions so that I don't have to repeatedly grab the W2 world object. It also allows be to check if any particular alias in W1 calls W2_do without having any case (i.e., if or elseif condition - e.g., line = "r") attached to it.


(2) From your third post (most recent) - "I'm not sure why you are calling rescue_sev with 3 arguments. Aliases and triggers, when called by MUSHclient, are passed 3 arguments, but there is no reason why your own functions have to have that many."

I do this as the scripts (e.g., rescue_sev) in W2 may also be called via triggers/aliases in W2.


(3) From your third post (most recent) - "Your use of nil is confusing too, because nil is really a Lua concept."

Your right. I just picked it up from somewhere - and am not sure where! I'll change "nil" to "nothing" (is that the proper syntax)?


(4) From your third post (most recent) - in relation to: w2.execute "/rescue_sev """ & wildcards (1) & "", nil, nil" ... "The use of the quotes is a bit confusing because you have to double them, as the line itself is quoted."

w2.execute "/rescue_sev " & "" & wildcards (1) & "", nil, nil"
... is how I interpret what you said.


As always, I am very greatful for your help and comments. My goal is essentially to seek more effective ways to fully automate W2 (and semi-automate W1).

Thanks
Sev
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Fri 13 Apr 2007 07:21 AM (UTC)
Message
Quote:

w2.execute "/rescue_sev " & "" & wildcards (1) & "", nil, nil"
... is how I interpret what you said.


You have removed a quote, but I think I got it wrong too. Bearing in mind that "" (2 quotes) inside a quoted string turns into one quote, to put a quote into a quoted string, and terminate the string at the same moment, we need 3 quotes.


w2.execute "/rescue_sev " & """ & wildcards (1) & """, nil, nil"


Personally I would use Lua nowadays and not VBscript. For one thing, you can use the "other" quote to make it less confusing:

Lua version:


w2.Execute ('/rescue_sev " ' .. wildcards [1] .. ' ", nil, nil')


I added a space to make it a bit clearer. The symbol ".." is concatenation in Lua.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Sev   (8 posts)  [Biography] bio
Date Reply #10 on Fri 13 Apr 2007 08:29 AM (UTC)
Message
Hi Nick,

Also ... in the help file on Triggers (in Mushclient) ... it states that a script called via a trigger should be in ther form: sub MyTrigger (name, line, wildcards). However, in your example, you have:

w2.execute "/rescue_sev " & """ & wildcards (1) & """, nil, nil"

Why are the wildcards passed first? Which parameter being sent is meant for which input parameter?

For convenience, lets formalise as follows:
Calling line:
w2.execute "/w2_script " OUT_PARA1, OUT_PARA2, OUT_PARA3"
Script being called:
sub w2_script (IN_PARA1, IN_PARA2, IN_PARA3)

... so which OUT_PARA is being passed to which IN_PARA?

Again, thanks.
Sev
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Fri 13 Apr 2007 09:26 PM (UTC)
Message
Sorry, I didn't realise at the time it was supposed to be mimicing a trigger. In that case, the wildcards should be the last argument.

However you have a bit of a problem here. Wildcards is a table, and you can't readily pass a table down (especially a VB table).

Effectively you want to call:


w2.execute "/w2_script name, line, wildcards"


But you can't literally code that, because then w2_script simply gets sent "name" not what "name" has in it. Also, wildcards is an array and not a single value. So it will look more like:


w2.Execute "/w2_script """, & name & """, """ & line & """, """ & wildcards (1) & """


This would handle sending down the name, the line, and the first wildcard.

- 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.


28,219 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]