Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Jun 25, 2009 3:02 am   

VBScript Question
 
How do I call a zscript function or alias from VBScript? I want to use VBScript dialogs for a series of questions and create a setup script. The zscript dialogs really irritate me to be honest and lack the functionality I want. For example, the message box in zscript is horrible. Yes I know it is just a simple popup. However, take the #yesno in zscript. You can't even use a local variable so you have to create a bunch of global variables just to answer a simple question and with VBScript it is very simple.

Code:
response = Msgbox ("Do you want to run setup?", vbYesNo, "Installation")
If response = vbYes Then
  MsgBox("You answered Yes)
Else
  MsgBox("You answered No")
End If


or

Code:
answer = MsgBox("Hello! " & Chr(13) & "Would you like to run setup?",4,"Example")
If answer = vbYes Then
    city = InputBox("Enter your city name:")
    zvar.cityName = city
    MsgBox("You entered " & city)
    guild = InputBox("Enter your guild name:")
    zvar.guildName = guild
    MsgBox("You entered " & guild)
Else
  MsgBox("Goodbye!")
End If


How simple is that?

The only problem is I don't know how you call a function. If the answer is yes to a specific question, I would like to call a function or alias specific to that question such as when I want to fill in a database from a list etc.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Jun 25, 2009 5:34 am   
 
You'll have to use the COM object model. This should give you a basic idea. http://forums.zuggsoft.com/forums/viewtopic.php?p=97090
_________________
Asati di tempari!
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Jun 25, 2009 8:35 am   
 
Maybe I am dumb but that doesn't tell me much. If you run that example, you get an error that object required: 'ss'

I can't figure out how you assign a value to a datarecord variable or stringlist in VBScript either.

In zscript prompt you have to create a new global variable just to assign a value of the input to a stringlist because a local variable won't work.

I guess I am just missing something or making this all too complicated. I get sick of doing something ten different ways where it should be simple.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Jun 25, 2009 10:18 am   
 
Okay well I guess I did confuse myself. I figured out how to do the prompt to add an item to a stringlist in zscript using the function version prompt instead of the command.

Example:
Code:
#additem itemList %prompt("","Enter the ID number of your item:")
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Jun 25, 2009 1:36 pm   
 
I'm sorry but this is really making me mad.

Why doesn't this work?

Code:
#yesno "Do you have a pack?" {pack = %prompt("","Enter the ID number of your pack:")}


It ends up putting the command for yes answer as the input box ok button text. Hence, another reason I wanted to just use VBScript, but everything is so tied to zscript its difficult to use another scripting language, which I find to be a downside to Cmud honestly. Even with Lua you have to still use zs.var and crap.

Apparently this does work:

Code:
#if (%yesno("Do you have a pack?")) {pack = %prompt("","Enter the ID number of your pack:")}


Someone please explain the difference...
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Jun 25, 2009 5:44 pm   
 
Quote:
but everything is so tied to zscript its difficult to use another scripting language, which I find to be a downside to Cmud honestly

No other program is going to be any better. What is VBScript? It's just a different "syntax" for programming. VBScript doesn't come with any built-in functions for talking with CMUD. Nor does JScript or Lua or any other programming language. What programming language comes with built-in access to a MUD client? None!

The only way to control an application like CMUD from *any* scripting language is to build an API for the application. That is what the COM system is that Tech linked to. That is what the "zvar" interface is also for. And that is what the whole "zs.*" interface for Lua is for. The COM API is old and was developed for zMUD, but works with any language supported by the Microsoft Scripting Host (VBScript, JScript, Perl, etc). The "zs.*" API was developed specifically for Lua to get around the limitations of the Microsoft Scripting Host. The "zs.*" API is not available to languages like VBScript because they use the Microsoft scripting interface (which Microsoft doesn't even support officially any more and doesn't provide any alternative for anymore).

Quote:
However, take the #yesno in zscript. You can't even use a local variable so you have to create a bunch of global variables

Use %yesno instead of #YESNO. The #YESNO command supports some obscure syntax for zMUD compatibility that sometimes causes problems. But you can still do:
Code:
$pack = %yesno("Do you have a pack?")

to use a local variable. You don't need to only use session variables.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Jun 25, 2009 11:06 pm   
 
Well I understand that. I guess my real problem is the fact that I can't find any of that information in the help files that explains how to use that interface. You offer the ability to script in VBScript, JScript, Lua, and Python but the only documentation you can find is for Lua.

Just like one programming language isn't perfect for everything, neither are scripting languages. I much prefer VBScripts msgbox and input boxes over the zscript ones. I can put multiple lines in them and they look much better. If you try and put for example multiple lines in the zscript input box the seconde line is half hidden behind the textbox. In VBScript I can add 10 lines if I want to.

I disagree that no other program is going to be better. The scripting interface in MUSH client is much better, and no I'm not saying MUSH client itself is better because I don't think it is. However, there is also much better information on how to use the various scripting languages that people might be used to using as well. Also GetVariable and SetVariable are far easier to understand for just about anyone and that is exactly how you do it with every scripting language in MUSH.

Take this example setting a variable in MUSH:

Quote:
VBscript example

world.SetVariable "MyName", "Nick Gammon"


Jscript example

world.SetVariable("MyName", "Nick Gammon");


PerlScript example

$world->SetVariable("MyName", "Nick Gammon");


Python example

world.SetVariable("MyName", "Nick Gammon")


Lua example

SetVariable ("MyName", "Nick Gammon")


or setting an array value

Quote:
VBscript example

ArraySet "spells", "dragonskin", "45"


Lua example

ArraySet ("spells", "dragonskin", "45")


I still have no idea how to set a datarecord value with VBScript in Cmud.

I don't understand this either...

Quote:
The COM API is old and was developed for zMUD, but works with any language supported by the Microsoft Scripting Host (VBScript, JScript, Perl, etc).


Why? I thought Cmud was an entirely new client. Why use the old API developed for zMud?
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Jun 26, 2009 2:46 am   
 
Quote:
Why use the old API developed for zMud?

Umm, for backwards compatibility. That's very important for the large majority of CMUD users who moved from zMUD and have lots of existing scripts.

I'm not going to get into a discussion of "which is better" with you. But in my opinion, the CMUD VBScript syntax of
Code:
zvar.MyName = "Nick Gammon"

is far better than
Code:
world.SetVariable "MyName", "Nick Gammon"

But the interface that you see MUSHClient using is the same kind of COM-based interface that I'm talking about. It has limits. And while it's nice that Nick was able to develop a consistent API for both the Microsoft Scripting Host languages (like VScript) and for Lua, I focused CMUD on Lua because I didn't want to keep dealing with the problems of the Microsoft system. That is why CMUD has a much richer Lua interface.

Sorry you like VBScript so much, but most people are learning and using Lua these days. I'm not going to waste my limited time and energy on Microsoft scripting languages when there are far superior alternatives. Have you tried using Lua to handle your multiline prompts?

The reason you can't use Local Variables in other scripting languages is because Local variables are *LOCAL*! They are internal to the compiler engine itself. There is no way to access them from anything outside of a compiled zScript. That is why they are so fast. It's just like asking why you can't access VBScript variables from a Lua script...you just can't. Languages are not designed with that kind of cross access. So zScript is no different.

In any case, this is getting off topic. Your example:
Code:
#if (%yesno("Do you have a pack?")) {pack = %prompt("","Enter the ID number of your pack:")}

works fine and that is the way you are supposed to do it. Use the %yesno and %prompt functions rather than the #YESNO and #PROMPT commands and you will be fine. If you need the multiline prompts, then use VBScript with regular session variables. If you turn on the "Use Default" option for the session variables, then the session variable will be very fast since it won't be saved across sessions. Or turn off "Use Default" to save variables across sessions.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Fri Jun 26, 2009 4:09 am   
 
Quote:
The reason you can't use Local Variables in other scripting languages is because Local variables are *LOCAL*! They are internal to the compiler engine itself. There is no way to access them from anything outside of a compiled zScript. That is why they are so fast. It's just like asking why you can't access VBScript variables from a Lua script...you just can't. Languages are not designed with that kind of cross access. So zScript is no different.


I'm not sure why are getting defensive and acting like I am retarded. Obviously I know what local variables are. So I don't know why you even brought this up. I was talking about using a local variable with the #prompt command in zscript not another scripting language like the following which doesn't work.

Code:
#local $item
#prompt $item "Enter the ID number of your item:"
#additem itemList $item


Quote:
...works fine and that is the way you are supposed to do it. Use the %yesno and %prompt functions rather than the #YESNO and #PROMPT commands and you will be fine.


My question was why and that is where my whole confusion and frustration started. I just switched to using the functions and yeah they work.

Quote:
But the interface that you see MUSHClient using is the same kind of COM-based interface that I'm talking about. It has limits. And while it's nice that Nick was able to develop a consistent API for both the Microsoft Scripting Host languages (like VScript) and for Lua, I focused CMUD on Lua because I didn't want to keep dealing with the problems of the Microsoft system. That is why CMUD has a much richer Lua interface.

Sorry you like VBScript so much, but most people are learning and using Lua these days. I'm not going to waste my limited time and energy on Microsoft scripting languages when there are far superior alternatives. Have you tried using Lua to handle your multiline prompts?


I understand about the interface. My problem was the fact there is no documentation and MUSH HAS a consistant interface that is easy to use AND documentation. I realize you have limited time. However, many people are drawn away by this.

I also never said I like VBScript so much. I'm not sure why you stated that. I said every scripting language has its benefits and I just happen to like VBScript for the message and input boxes. I also agree they are learning to use Lua but when I tried to create an entire system in Lua I ran into nothing but bugs and couldn't find decent documentation at that time and went back to zscript. Now yes you have fixed those bugs in the beta versions and some more documentation was added. Great! I also have limited time too and don't want to write stuff to do work around constantly and then have to go back and change everything again and again and again.

I also understand "use default" and use it on most all of my variables. Again I am not retarded.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Jun 29, 2009 5:41 pm   
 
Btw, here is another "trick" for using the VBScript InputBox to store a value into a LOCAL variable:
Code:
$local = %mss("InputBox(""Enter your city name:"")", "vbscript")

The %mss function evaluates an expression in another scripting language and returns the result, which is then assigned to a local variable.

Quote:
Again I am not retarded.

Sorry, I didn't mean to imply that. I just couldn't figure out what you were really complaining about. You first complained that the zscript dialogs were irritating you and that you wanted to call InputBox or something in VBScript, but that you couldn't do that with Local Variables. Then you asked about calling zscript commands/functions from VBScript, but couldn't understand the example thread that Tech posted that showed how to call the #STATE command from VBScript. Then you complained about the #YESNO command even though you answered your own question with your correct %yesno example. Then you started bashing the zScript interface and comparing it to MUSHclient.

Better (but old) documentation for the VBScript (Microsoft scripting interface) API can be found here: http://www.zuggsoft.com/page.php?file=zmud/comserve.htm where you replace most instances of "zmud" with "cmud".

Quote:
I realize you have limited time. However, many people are drawn away by this.

It is correct that I have limited time. It is incorrect that "many people are drawn away by this". I've been writing zMUD and CMUD and documenting them over 14 years now, and they have never been documented "enough" nor will they ever be. There is never any end to documentation. And actually, most people don't even bother reading the documentation anyway. CMUD already has far more documentation than any other MUD client. Gurus have helped a lot with it in the past, and anyone else who wants to volunteer to work on it can do so. My limited time is better spent on bug fixes which nobody else can help with. Historically, improving the documentation has never resulted in increased sales.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net