• Welcome to Valhalla Legends Archive.
 

VBScript, Accessing another Sub

Started by CrAz3D, March 23, 2004, 07:18 PM

Previous topic - Next topic

CrAz3D

I have my VBScript code loaded from a text File
Sub OnTalk(Username, Flags, Message, Ping)
   if username = "CrAz3D[xL]" then
      form1.addchat vbred, message & "::" & username
   end if
end sub


Upon the users talking in the channel it calls that code.  What I'm not sure how to do is how to add my Ban sub, which is located in a Module, to the msscript to allow the VBScript Code to use the Ban sub.

Any helpful tips?
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

UserLoser.

#1
Not sure about modules, but if it's in a Class Module then you can do it.  Here's my example:

Some other global module...

Global LocalCommand as CLocalCommands

---
The sub where you initialize & load the scripts:

Set LocalCommand = New CLocalCommands
MyScript.AddObject "CommandProcessor", LocalCommand, True


Then you can do:

Sub User_Talk(Username, Text, Flags, Ping)
  If InStr(1, Username, "xL", 1) Then
     CommandProcessor.ProcessCommand "ban " & Username & " ew"
  End If
Exit Sub

CrAz3D

This works for anything in classes, does anyone have something that might work for modules?
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Stealth

I don't believe you can do it in modules. The Script control only allows you to "expose" objects, including classes and form controls, to it.

The solution? Write a wrapper class such as StealthBot's ScriptSupportClass.txt. You can find ScriptSupportClass.txt (which is basically the class' source code) at http://cold-chaos.net/stealth/ScriptSupportClass.txt or installed with any copy of StealthBot.
- Stealth
Author of StealthBot

CrAz3D

Quote from: Stealth on March 23, 2004, 09:30 PM
I don't believe you can do it in modules. The Script control only allows you to "expose" objects, including classes and form controls, to it.

The solution? Write a wrapper class such as StealthBot's ScriptSupportClass.txt. You can find ScriptSupportClass.txt (which is basically the class' source code) at http://cold-chaos.net/stealth/ScriptSupportClass.txt or installed with any copy of StealthBot.

I've looked through this, what I am wondering is how you called the GetAccess function, or your Ban sub.
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Fr0z3N

#5
Quote from: UserLoser. on March 23, 2004, 07:21 PM
Then you can do:

Sub User_Talk(Username, Text, Flags, Ping)
  If InStr(1, Username, "xL", 1) Then
     CommandProcessor.ProcessCommand "ban " & Username & " ew"
  End If
Exit Sub


Jerk lol

;)

Stealth

Quote from: CrAz3D on March 23, 2004, 10:17 PM
I've looked through this, what I am wondering is how you called the GetAccess function, or your Ban sub.

The class is instantiated within my program. Classes, as a part of your program, can call public methods contained within modules (as GetAccess and Ban are). You write the wrapper functions because the script control can only access what it can see.

Think of it like this: (No smart comments ;) )
Your program is a car. The script control is in the trunk. It can't see the rest of the car -- only other things you put in the trunk. ScriptSupportClass (and similar wrappers) are like adding a small passageway between the trunk and the body of the car. Through this passage you can see a very limited bit of the inside of the car, but still not the majority of its interior.

Your wrapper class acts as a window to the rest of your program's code. You decide what the script control gets to see and what it doesn't get to see -- by controlling what functions you add to the wrapper class, you control the size and shape of the window into the body of the car.

HTH.
- Stealth
Author of StealthBot

UserLoser.

Can add anything that's an object, which modules are not (like stated above a few times):

ScriptControl.AddObject "NameToUseInScripting", frmMain.MyObject, True 'Forgot what the boolean is for off the top of my head
ScriptControl.AddObject "PacketBuffer", MyPacketBufferClass, True
ScriptControl.AddObject "UserLiser", frmMain.lvwUsers, True


ect.

CrAz3D

Quote from: Stealth on March 23, 2004, 11:12 PM
Quote from: CrAz3D on March 23, 2004, 10:17 PM
I've looked through this, what I am wondering is how you called the GetAccess function, or your Ban sub.

The class is instantiated within my program. Classes, as a part of your program, can call public methods contained within modules (as GetAccess and Ban are). You write the wrapper functions because the script control can only access what it can see.

Think of it like this: (No smart comments ;) )
Your program is a car. The script control is in the trunk. It can't see the rest of the car -- only other things you put in the trunk. ScriptSupportClass (and similar wrappers) are like adding a small passageway between the trunk and the body of the car. Through this passage you can see a very limited bit of the inside of the car, but still not the majority of its interior.

Your wrapper class acts as a window to the rest of your program's code. You decide what the script control gets to see and what it doesn't get to see -- by controlling what functions you add to the wrapper class, you control the size and shape of the window into the body of the car.

HTH.


Oh, makes sense.  But how do you encorporate your ScriptSupportClass into your program, so that it works as a class?
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Stealth

It's just an ordinary .cls class file. Public ScriptSupportClass as clsScriptSupportClass in a module, then on Form_Load() I initialize it (set ScriptSupportClass = new ScriptSupportClass) and on Form_Unload() I erase it (Set ScriptSupportClass = nothing). Then, when the script control is initialized I pass it as an object, as UserLoser described above.
- Stealth
Author of StealthBot

CrAz3D

okey dokey, quite dandy.

I'll see what I can do.

Thank you very much indeed.
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...