has anyone been able to successfully define a class in a DC hub script?
I have attempted to do so and I get an "Unrecognized Object" error, meaning it doesn't realize that I've defined that class. Any clues as to how I can use my own class?
I will distro the script if I pull it off. It will be a nice fun little script.
Using Classes
Moderator: Moderators
well shoot. Then I don't see any reason why I should be getting an error.
I have this script I wrote, but it gives me an error when I try to access the class, not when I set it.
'~~~~~~~~~~~~~~~~~~~User Notes~~~~~~~~~~~~~~~~~~~~~~~~~~
'Sardonis' Mimic v1.4 (inoperable)
'Date: 2/07/03
'Email: [email protected]
'Webpage: http:\\www.neural-interface.com\newhaven\
'This script creates a command with a special form that will allow any user to make any name say anything in the main chat,
'There is, however, a catch, you can't use this command unless you can figure out the answer to the clue.
'I am currently modifying my original code to allow for arrays in stack form, so that mods can add clues in series.
'The script will also automatically change the clue/command set 48 hours after 3 users figure out the answer
'~~~~~~~~~~~~~~~~~~~~~~Global Vars~~~~~~~~~~~~~~~~~~~~~~
Dim aCommand
Const sBotName = "God"
Const descriptrigger = "!mimic" 'Command that triggers the description
Dim description 'change in sub main, describes the mimic trigger.
Dim aOps
Dim aClue
Dim aGurus(4) 'list of the first 3 who've used the command since it last switched, the fourth item, if present will be the time the 3rd user first used the command
'~~~~~~~~~~~~~~~~~~~~~~Classes~~~~~~~~~~~~~~~~~~~~~~~~~~~
Class WeakList
'********* MEMBER VARIABLES **********
Private dynArray
'*************************************
'********* EVENT HANDLERS ************
Private Sub Class_Initialize()
'Allocate the dynamic array instance
Set dynArray = New DynamicArray
End Sub
Private Sub Class_Terminate()
Set dynArray = Nothing 'Clean up!
End Sub
'*************************************
'************ PROPERTIES *************
Public Property Get Count()
Count = dynArray.StopIndex() - dynArray.StartIndex()
End Property
'Public Property Get value(x)
' value=dynArray.Data(x)
'End Property
'*************************************
'************* METHODS ***************
Public Sub AddHead(varItem)
'Add an element to the start of the arrray
'Start by moving all of the elements down on position
Dim iLoop
For iLoop = dynArray.StopIndex() to dynArray.StartIndex() STEP -1
dynArray.Data(iLoop + 1) = dynArray.Data(iLoop)
Next
'Insert varItem at the head
dynArray.Data(dynArray.StartIndex()) = varItem
End Sub
Public Function RemoveHead()
'Remove and return the element from the start of the array
'Don't do this if StopIndex() < StartIndex()
If dynArray.StopIndex() > dynArray.StartIndex() then
RemoveHead = dynArray.Data(dynArray.StartIndex())
dynArray.Delete(dynArray.StartIndex())
End If
End Function
Public Sub AddTail(varItem)
'Add an element to the end of the array
dynArray.Data(dynArray.StopIndex()) = varItem
End Sub
Public Function RemoveTail()
'Remove and return the element from the end of the array
'Don't do this if StopIndex() < StartIndex()
If dynArray.StopIndex() > dynArray.StartIndex() then
RemoveTail = dynArray.Data(dynArray.StopIndex() - 1)
dynArray.Delete(dynArray.StopIndex() - 1)
End If
End Function
Public Function PeekHead()
'Return the element at the head of the array
'Don't do this if StopIndex() < StartIndex()
If dynArray.StopIndex() > dynArray.StartIndex() then
PeekHead = dynArray.Data(dynArray.StartIndex())
End If
End Function
Public Function PeekTail()
'Return the element at the end of the array
'Don't do this if StopIndex() < StartIndex()
If dynArray.StopIndex() > dynArray.StartIndex() then
PeekTail = dynArray.Data(dynArray.StopIndex() - 1)
End If
End Function
'*************************************
End Class
'~~~~~~~~~~~~~~~~~~~~~~~Developer Notes~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Commands to add:
'!ListTriggers list all the available triggers
'!Save (op only) will manually save the current command/clue list (just in case)
'!GetCommand (op only) will retrieve what the current mimic command is
'!AddCommand [command] [clue](op only) will add a command to the command/clue list
'!RemoveLast (op only) removes the last command added from the list
'!NextCommand (op only) retrieves a new command from the stack, dropping the current one into the endless abyss
'!ListGurus lists those who have used the current command
'!ViewNext (op only) shows what the next command will be (maybe?)
Sub Main()
description="Yes, the rumor is true. There is a command in this hub that allows you to chat as another user. It gets changed 48 hours after 3 people discover the answer to the clue. In order to use the command, send a Private Message to God in the form of " & vbCrLf & "-[clue_answer] [user_name] %s%[Message you want them to say]" & vbCrLF & "The command will always be all lowercase."
frmHub.RegisterBotName(sBotName)
Load
Set aCommand = New WeakList
Set aClue = New WeakList
dim cmd
dim clu
cmd="mr_sluggles"
clu="This cuddly creature is the pet of one of the admins. Find the answer at: http://www.neural-interface.com/newhaven"
AddOne cmd,clu
aOps=Array("NI","Sardonis","Majickmrkr","Mr.Fixit","Quadra","Telepathetic","[NH]OC3Serve")
'the ops will be able to modify commands and will not be counted in the 3 people needed to cause the command to change
End Sub
Sub DataArival (curUser, sCurData)
dim sText
dim sName
dim sMsg
If Left(sCurData, = "$To: " & sBotName then
sText=Trim(AfterFirst(sCurData,"> ")) & " "
sMsg=GetnRemoveB4(sText," ")
If Left(sMsg, Len(aCommand)) = aCommand then
sText=AfterFirst(sText, " ")
sName=Beforefirst(sText, " ")
sText=AfterFirst(sText, "%s%")
colusers.sendchattoall cstr(sName),cstr(sText)
sMsg=curUser.sName & " made " & sName & " say: " & sText
SendMsg "Sardonis",sMsg
SendMsg "majickmrkr",sMsg
SendMsg "Telepathetic",sMsg
End if
Elseif Left(sCurData, ="<" then
sText=Trim(AfterFirst(sCurData,"> ")) & " "
sMsg=BeforeFirst(sText," ")
Select Case(sMsg)
Case "!clue"
colusers.sendtoall cstr(aClue.PeekHead)
Case descriptrigger
colusers.sendtoall cstr(description)
End Select
End if
End Sub
Function BeforeFirst(sIn, sFirst) 'These are helper functions and do what their names imply
BeforeFirst = Left(sIn, InStr(1, sIn, sFirst) - 1)
End Function
Function AfterFirst(sIn, sFirst)
AfterFirst = Right(sIn, Len(sIn) - InStr(1, sIn, sFirst) - (Len(sFirst) - 1))
End Function
Public Function AfterLast(sFrom, sAfterLast)
If InStr(1, sFrom, sAfterLast) Then
AfterLast = Right(sFrom, Len(sFrom) - InStrRev(sFrom, sAfterLast) - (Len(sAfterLast) - 1))
Else
AfterLast = ""
End If
End Function
Public Function sReplace(sIn, sWhat, sWith)
sReplace = sIn
Do While InStr(1, sReplace, sWhat) <> 0
sReplace = BeforeFirst(sReplace, sWhat) & sWith & AfterFirst(sReplace, sWhat)
Loop
End Function
Public Function ReplaceVars(sMessage, sCurData)
Dim sUser
Dim sText
sText = AfterFirst(sCurData, "> ")
sUser = BeforeFirst(AfterFirst(sCurData, "<"), ">")
ReplaceVars = sMessage
ReplaceVars = sReplace(ReplaceVars, "%USER%", sUser)
ReplaceVars = sReplace(ReplaceVars, "%ECHO_TEXT%", sText)
End Function
Public Sub SendMsg(sRecipient,sMsg)
Dim usr
Set usr = colusers.ItemByName(cstr(sRecipient))
usr.PrivateMessage cstr(sBotName),cstr(sMsg)
End Sub
Function GetnRemoveB4(sFrom, sIn)
GetnRemove=BeforeFirst(sFrom,sIn)
sFrom=AfterFirst(sFrom,sIn)
End Function
Public Sub AddOne(sCommand,sClue)
On Error Resume Next
sCommand="-" & sCommand
aCommand.AddTail(sCommand) 'error here "Unrecognized Object"
aClue.AddTail(sClue)
SendMsg "Sardonis",cstr(Err.Description)
Err.Clear
End Sub
'XXXXXXXThese will have to be written after the class is made to work, but assuming that
'XXXXXXXis done I would appreciate someone to write this bit of code for me and some code
'XXXXXXXto change the command 48 hours after a time has been set. I plan to store the time
'XXXXXXXof the third discovery in a text file after the list of the first 3 users to
'XXXXXXXdiscover the current command. A second text file will hold the list of commands
'XXXXXXXand clues.
Public Sub Save()
End Sub
Public Sub Load()
End Sub
I have this script I wrote, but it gives me an error when I try to access the class, not when I set it.
'~~~~~~~~~~~~~~~~~~~User Notes~~~~~~~~~~~~~~~~~~~~~~~~~~
'Sardonis' Mimic v1.4 (inoperable)
'Date: 2/07/03
'Email: [email protected]
'Webpage: http:\\www.neural-interface.com\newhaven\
'This script creates a command with a special form that will allow any user to make any name say anything in the main chat,
'There is, however, a catch, you can't use this command unless you can figure out the answer to the clue.
'I am currently modifying my original code to allow for arrays in stack form, so that mods can add clues in series.
'The script will also automatically change the clue/command set 48 hours after 3 users figure out the answer
'~~~~~~~~~~~~~~~~~~~~~~Global Vars~~~~~~~~~~~~~~~~~~~~~~
Dim aCommand
Const sBotName = "God"
Const descriptrigger = "!mimic" 'Command that triggers the description
Dim description 'change in sub main, describes the mimic trigger.
Dim aOps
Dim aClue
Dim aGurus(4) 'list of the first 3 who've used the command since it last switched, the fourth item, if present will be the time the 3rd user first used the command
'~~~~~~~~~~~~~~~~~~~~~~Classes~~~~~~~~~~~~~~~~~~~~~~~~~~~
Class WeakList
'********* MEMBER VARIABLES **********
Private dynArray
'*************************************
'********* EVENT HANDLERS ************
Private Sub Class_Initialize()
'Allocate the dynamic array instance
Set dynArray = New DynamicArray
End Sub
Private Sub Class_Terminate()
Set dynArray = Nothing 'Clean up!
End Sub
'*************************************
'************ PROPERTIES *************
Public Property Get Count()
Count = dynArray.StopIndex() - dynArray.StartIndex()
End Property
'Public Property Get value(x)
' value=dynArray.Data(x)
'End Property
'*************************************
'************* METHODS ***************
Public Sub AddHead(varItem)
'Add an element to the start of the arrray
'Start by moving all of the elements down on position
Dim iLoop
For iLoop = dynArray.StopIndex() to dynArray.StartIndex() STEP -1
dynArray.Data(iLoop + 1) = dynArray.Data(iLoop)
Next
'Insert varItem at the head
dynArray.Data(dynArray.StartIndex()) = varItem
End Sub
Public Function RemoveHead()
'Remove and return the element from the start of the array
'Don't do this if StopIndex() < StartIndex()
If dynArray.StopIndex() > dynArray.StartIndex() then
RemoveHead = dynArray.Data(dynArray.StartIndex())
dynArray.Delete(dynArray.StartIndex())
End If
End Function
Public Sub AddTail(varItem)
'Add an element to the end of the array
dynArray.Data(dynArray.StopIndex()) = varItem
End Sub
Public Function RemoveTail()
'Remove and return the element from the end of the array
'Don't do this if StopIndex() < StartIndex()
If dynArray.StopIndex() > dynArray.StartIndex() then
RemoveTail = dynArray.Data(dynArray.StopIndex() - 1)
dynArray.Delete(dynArray.StopIndex() - 1)
End If
End Function
Public Function PeekHead()
'Return the element at the head of the array
'Don't do this if StopIndex() < StartIndex()
If dynArray.StopIndex() > dynArray.StartIndex() then
PeekHead = dynArray.Data(dynArray.StartIndex())
End If
End Function
Public Function PeekTail()
'Return the element at the end of the array
'Don't do this if StopIndex() < StartIndex()
If dynArray.StopIndex() > dynArray.StartIndex() then
PeekTail = dynArray.Data(dynArray.StopIndex() - 1)
End If
End Function
'*************************************
End Class
'~~~~~~~~~~~~~~~~~~~~~~~Developer Notes~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Commands to add:
'!ListTriggers list all the available triggers
'!Save (op only) will manually save the current command/clue list (just in case)
'!GetCommand (op only) will retrieve what the current mimic command is
'!AddCommand [command] [clue](op only) will add a command to the command/clue list
'!RemoveLast (op only) removes the last command added from the list
'!NextCommand (op only) retrieves a new command from the stack, dropping the current one into the endless abyss
'!ListGurus lists those who have used the current command
'!ViewNext (op only) shows what the next command will be (maybe?)
Sub Main()
description="Yes, the rumor is true. There is a command in this hub that allows you to chat as another user. It gets changed 48 hours after 3 people discover the answer to the clue. In order to use the command, send a Private Message to God in the form of " & vbCrLf & "-[clue_answer] [user_name] %s%[Message you want them to say]" & vbCrLF & "The command will always be all lowercase."
frmHub.RegisterBotName(sBotName)
Load
Set aCommand = New WeakList
Set aClue = New WeakList
dim cmd
dim clu
cmd="mr_sluggles"
clu="This cuddly creature is the pet of one of the admins. Find the answer at: http://www.neural-interface.com/newhaven"
AddOne cmd,clu
aOps=Array("NI","Sardonis","Majickmrkr","Mr.Fixit","Quadra","Telepathetic","[NH]OC3Serve")
'the ops will be able to modify commands and will not be counted in the 3 people needed to cause the command to change
End Sub
Sub DataArival (curUser, sCurData)
dim sText
dim sName
dim sMsg
If Left(sCurData, = "$To: " & sBotName then
sText=Trim(AfterFirst(sCurData,"> ")) & " "
sMsg=GetnRemoveB4(sText," ")
If Left(sMsg, Len(aCommand)) = aCommand then
sText=AfterFirst(sText, " ")
sName=Beforefirst(sText, " ")
sText=AfterFirst(sText, "%s%")
colusers.sendchattoall cstr(sName),cstr(sText)
sMsg=curUser.sName & " made " & sName & " say: " & sText
SendMsg "Sardonis",sMsg
SendMsg "majickmrkr",sMsg
SendMsg "Telepathetic",sMsg
End if
Elseif Left(sCurData, ="<" then
sText=Trim(AfterFirst(sCurData,"> ")) & " "
sMsg=BeforeFirst(sText," ")
Select Case(sMsg)
Case "!clue"
colusers.sendtoall cstr(aClue.PeekHead)
Case descriptrigger
colusers.sendtoall cstr(description)
End Select
End if
End Sub
Function BeforeFirst(sIn, sFirst) 'These are helper functions and do what their names imply
BeforeFirst = Left(sIn, InStr(1, sIn, sFirst) - 1)
End Function
Function AfterFirst(sIn, sFirst)
AfterFirst = Right(sIn, Len(sIn) - InStr(1, sIn, sFirst) - (Len(sFirst) - 1))
End Function
Public Function AfterLast(sFrom, sAfterLast)
If InStr(1, sFrom, sAfterLast) Then
AfterLast = Right(sFrom, Len(sFrom) - InStrRev(sFrom, sAfterLast) - (Len(sAfterLast) - 1))
Else
AfterLast = ""
End If
End Function
Public Function sReplace(sIn, sWhat, sWith)
sReplace = sIn
Do While InStr(1, sReplace, sWhat) <> 0
sReplace = BeforeFirst(sReplace, sWhat) & sWith & AfterFirst(sReplace, sWhat)
Loop
End Function
Public Function ReplaceVars(sMessage, sCurData)
Dim sUser
Dim sText
sText = AfterFirst(sCurData, "> ")
sUser = BeforeFirst(AfterFirst(sCurData, "<"), ">")
ReplaceVars = sMessage
ReplaceVars = sReplace(ReplaceVars, "%USER%", sUser)
ReplaceVars = sReplace(ReplaceVars, "%ECHO_TEXT%", sText)
End Function
Public Sub SendMsg(sRecipient,sMsg)
Dim usr
Set usr = colusers.ItemByName(cstr(sRecipient))
usr.PrivateMessage cstr(sBotName),cstr(sMsg)
End Sub
Function GetnRemoveB4(sFrom, sIn)
GetnRemove=BeforeFirst(sFrom,sIn)
sFrom=AfterFirst(sFrom,sIn)
End Function
Public Sub AddOne(sCommand,sClue)
On Error Resume Next
sCommand="-" & sCommand
aCommand.AddTail(sCommand) 'error here "Unrecognized Object"
aClue.AddTail(sClue)
SendMsg "Sardonis",cstr(Err.Description)
Err.Clear
End Sub
'XXXXXXXThese will have to be written after the class is made to work, but assuming that
'XXXXXXXis done I would appreciate someone to write this bit of code for me and some code
'XXXXXXXto change the command 48 hours after a time has been set. I plan to store the time
'XXXXXXXof the third discovery in a text file after the list of the first 3 users to
'XXXXXXXdiscover the current command. A second text file will hold the list of commands
'XXXXXXXand clues.
Public Sub Save()
End Sub
Public Sub Load()
End Sub
theres no Delete or any other destructor simply NULL the values of the object e.g.
Code: Select all
Class TestClass
Private Sub Class_Initialize ' Setup Initialize event.
MsgBox("TestClass started")
End Sub
Private Sub Class_Terminate ' Setup Terminate event.
MsgBox("TestClass terminated")
End Sub
End Class
Set X = New TestClass ' Create an instance of TestClass.
Set X = Nothing ' Destroy the instance.
Need NOT Greed (don't abuse poor countries)
Pay the Poor (increase minimum wage)
Tax the Rich (100% SuperTax rate)
(Do ya think thats maybe a little left-wing?)
Pay the Poor (increase minimum wage)
Tax the Rich (100% SuperTax rate)
(Do ya think thats maybe a little left-wing?)
ok got it this time .. ignore my earlier posts i misunderstood the problem, your declaration of the new object is wrong it should be:
this is a VB-Script thing it needs the Dim before the Set, as for not being able to edit you posts I HATE IT, sorry but i'm totally in the habit of just using posts as a kinda notebook when i'm investigating something it really frikken annoys me that it dosn't work on this board as its the only one i use that doesn't allow editing I FRIKKEN HATE THIS STUPID BOARDS SETTINGS HATE HATE HATE
Code: Select all
Dim aCommand, aClue
Set aCommand = New WeakList
Set aClue = New WeakList
Need NOT Greed (don't abuse poor countries)
Pay the Poor (increase minimum wage)
Tax the Rich (100% SuperTax rate)
(Do ya think thats maybe a little left-wing?)
Pay the Poor (increase minimum wage)
Tax the Rich (100% SuperTax rate)
(Do ya think thats maybe a little left-wing?)