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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  issues with script called from alias
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

issues with script called from alias

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


Posted by Rayanth   (5 posts)  [Biography] bio
Date Fri 07 May 2004 02:35 AM (UTC)
Message
I'm having issues witha script that i'mc alling from an alias... I'm not sure if i set up the alias right or ...

Anyway, when i try this script (without the arguments in the definition or output) using Immediate, it works fine, but when i try to call it from a labeled alias on a menu, it fails, giving the following error

Error number: -2146828283
Event: Execution of line 148 column 1
Description: Invalid procedure call or argument: 'mid'
Called by: Function/Sub: getSelection called by alias
Reason: processing alias "cure"

for some reason it no longer likes the use of mid, even though it worked fine without the alias calling it...

here's the script

sub getSelection (thename, theoutput, thewildcards)

dim selLine
dim selTarget
dim selLength
selLine = GetLineInfo(GetSelectionStartLine, 1)
selLength = GetSelectionEndColumn - GetSelectionStartColumn
selTarget = mid(selLine, GetSelectionStartColumn, selLength)
world.note "Selected text is '" + selTarget + "'. thename is '" + thename + "'. theoutput is '" + theoutput + "'. thewildcards is '" + thewildcards + "'."

end sub


The idea here, is to Capture whatever is selected in teh output window, and execute commands on it. for instance if "Dreya" is highlighted, and I Ctrl-Click for the Alias menu, selecting "Cure" will send "Cast cure Dreya" to the world.

Another issue i'm running into, and hence the output of the arguments in this test version, is I want to use this one routine in one of two ways: either return the value of "selTarget" to the alias so the alias can use it to send to the world (not possible as far as i can tell) or use this one routine for multiple aliases, sending a different command to the world for each. ie, it would be used for "cast cure" for "identify" for "scrap" for "junk" ... etc. off the top of my head i can think of the following uses I would like for this one routine, witht he highlighted text in <>

cast cure <player>
cast armor <player>
(and other spells)
identify <object>
scrap <object>
junk <object>
put <object> in (alias-defined container)
put <object> in )other alias-defined containers)


Any input on why my current revision is failign on the mid line, or how i can get my ultimate goal to work (if possible) would be greatly appreciated =)
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #1 on Fri 07 May 2004 02:38 PM (UTC)
Message
Try this:


selTarget = mid(selLine, cint(GetSelectionStartColumn), cint(selLength))


I used the following from the input window in Mushclient to test my first hypothesis and it worked:


/world.note mid(GetLineInfo(GetSelectionStartLine, 1), cint(GetSelectionStartColumn), cint(GetSelectionEndColumn - GetSelectionStartColumn))
[Go to top] top

Posted by Rayanth   (5 posts)  [Biography] bio
Date Reply #2 on Sat 08 May 2004 03:40 AM (UTC)
Message
I tried both of your suggestions (adding cint to my existing line, and replaced my entire mid statement with yours) -- both work when done in Immediate, or called from /getSelection() (removing the arguments from the declaration) However, both still give the same error when trying to call them from an alias (with the arguments in place)

I'm wonder about two things. First off, I'm not positive I'm building the alias correctly, to call this - Any help on that would be greatly appreciated. Second -- I'm wondering if this might be some sort of bug. the Mid function obviously should exist, it's in the MSDN, and it works fine when called from command line... but somehow, after the alias is put into the chain of events, vbscript no longer recognizes Mid -- is this a result of something in the way the alias calls it, or a bug in mushclient, or a bug in vbscript? The world may never know.... But if you do know, I'm dying to figure this one out =)

Also, any other suggestions and workarounds for my intent (Stated in first post) would be helpful. I'm still not entirely positive that what I want to do, is possible to do... I'd know for sure, if I could tell what information the Alias sends to the function.. I suppose I can build a function that just does that. I'll do that now.

Also, any ideas if javascript has this same issue? perhaps if I use javascript it won't bug on this... I don't know javascript too well though.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #3 on Sat 08 May 2004 05:31 AM (UTC)
Message
OK, on the same issue of Mid... The problem lies in the selLine variable - if nothing is selected in the output window then that variable is passed into the Mid function as empty, which generates that error. Here's a simple check to safeguard against that happening:


sub getSelection (thename, theoutput, thewildcards)
	dim selLine
	dim selTarget
	dim selLength

	selLine = GetLineInfo(GetSelectionStartLine, 1)
	if IsEmpty(selLine) then
		exit sub
	end if

	selLength = GetSelectionEndColumn - GetSelectionStartColumn
	selTarget = mid(selLine, GetSelectionStartColumn, selLength)
end sub


I've omitted your last line with the world.Note, since there are problems with it also (something to do with the ' signs probably). Also, try to avoid using the + signs when concatenating strings together - vbscript being a dynamically typed language will complain about you adding a string and an int for example only at runtime, use & instead , that'll force everything to be automatically cast into strings.
[Go to top] top

Posted by Rayanth   (5 posts)  [Biography] bio
Date Reply #4 on Sat 08 May 2004 06:08 AM (UTC)
Message
Everey Time I tried it (and it failed) there was something selected. Thanks for pointing this out though, it brings that to my attention - the question now is, why does it think there's nothing seelcted?

The answer to that can only lie in the way GetSelection... routines work... since i'm calling the function through an alias, is the alias somehow preventing it from seeing selected text? or is the selection going away as the alias is called, and therefore there isn't really any seleceted text.... I suppose the latter is more likely, but can you offer any suggestions on getting around that? Keeping in midn that I'm trying to execute this using the Ctrl-Click Alias Menu...

Thanks again for your wonderful help, you're touching on things I didn't think to (or forgot to) consider...
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 08 May 2004 06:10 AM (UTC)
Message
The problem isn't the mid function, it is what is being passed to it.

You can test that by doing debugging displays, preferably using AppendToNotepad.

I suspect that we have another instance of a problem that occurred a while back (search for GetSelection in this forum). I suspect that entering a command cancels the selection, this was an earlier bug, which seems to have returned in some form. This is why it works from the Immediate window.

- Nick Gammon

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

Posted by Rayanth   (5 posts)  [Biography] bio
Date Reply #6 on Sat 08 May 2004 06:25 AM (UTC)
Message
I had seen that post re: GetSelection before which is why my last posted mused on that possibility.

I guess I'll just start looking for another way to do this. My original thought was to run it through a COM object to an external pluginb ut i wanted to try and do it internally first. The external program was going to be a second window, that contained in a listbox form, everything returned by the 'inventory' command, and allows for right-clicking any item and performing an action on it... it's about the best i can do i guess.

Once again, thanks for all the help =) I'll update if I stumble on a workaround or something.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #7 on Sat 08 May 2004 07:42 AM (UTC)
Message
Hmm, I swear that it works for me. Entering the alias does clear the selection but the sub doesn't exit on the empty check. I am using version 3.49, maybe that explains the difference in results?
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Sat 08 May 2004 07:43 AM (UTC)
Message
It works if you type the alias, it doesn't work for the ctrl+click menu.

That sounds like a bug, I'll look into it.

- Nick Gammon

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

Posted by Rayanth   (5 posts)  [Biography] bio
Date Reply #9 on Sat 08 May 2004 05:52 PM (UTC)
Message
to paraphrase from memory, the previous thread on GetSelection noted that the code was changed so that anything typed in the command line was processed before the selection was removed - that was a change in the order of operations in the mushclient code itself.

That would explain why it works if you type it in immediate, or by alias in the command line. However, since the post noted that it only changed the order for command line, and not anything else - i would suggest that Ctrl-Click is still beign processed /after/ the selection is removed.

Should be a simple fix, if that's the case. ame fix as for the command line, just drop Ctrl-Click in before selection's removed.

FWIW, i'm also using 3.49
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Mon 10 May 2004 09:30 PM (UTC)
Message
Yes, that is probably right.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Wed 26 May 2004 12:51 AM (UTC)
Message
Fixed in version 3.50 to call the alias before removing the selection.

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


7,619 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 FutureQuest]