Convert plugins

From StealthBot Wiki
Jump to: navigation, search

The plugin format is slightly different than the script format.

Here is a guide of changes that need to be done in order to convert a plugin to a script. These are general guidelines on how conversions should be done. If you'd like to change functionality or rewrite a script completely in the new script format, using these guidelines is not recommended if you would like to take full advantage of new script system features.

Plugin header to script header

A comment header is ignored by the script system, so the comments can be changed to whatever you want.</li> At the beginning of the new script, we need to populate the Script dictionary for the script system.

Example conversion:

'example
'1.63
'&Sample Plugin:SomePerson:This plugin is a sample used on the StealthBot Wiki.
'&example:samplecmd
'&9001
'&important note #1:important note #2

becomes:

Script("Name") = "Sample"
Script("Author") = "SomePerson"
Script("Major") = 1
Script("Minor") = 63
Script("Revision") = 1
Script("Description") = "This script is a sample used on the StealthBot Wiki."

The name should be one word or two. Do not make this excessively long or tedious because the internal script commands require the full name.

The author name should be kept as shown.

The major should be the number to the left of the dot, the minor should be the number to the right, and revision should be 1 since you are revising it but not changing the functionality.

StealthBot itself ignores the Description key, but some future scripts might use the field to present useful information to the user.

You may want to leave unconverted comments for later in case such a future script optionally checks for such information and you can put it in the Script object then.

Plugin prefixes

The prefix in front of all script events in the plugin must be removed to function. The prefix in front of global variable names, custom function names, and class names may be removed for readability. They are removable because the Script Control modules are each separate, and it is not possible for identifier names to conflict anymore. Important: all calls to changed variable names, function names, and class names must be changed also in uses of the variables and classes and calls to the functions in code.

Example conversion:

Private Const example_ConstantVar = "constantval"

Private example_GlobalVar

Sub example_Event_Load()
    Set example_GlobalVar = New clsExample_CustomClass
    Call example_CustomFunction1(example_ConstantVar)
End Sub

Function example_CustomFunction1(argA)
    ' code
End Function

Class clsExample_CustomClass
    ' code
End Class

becomes:

Private Const ConstantVar = "constantval"

Private GlobalVar

Sub Event_Load()
    Set GlobalVar = New clsCustomClass
    Call CustomFunction1(ConstantVar)
End Sub

Function CustomFunction1(argA)
    ' code
End Function

Class clsCustomClass
    ' code
End Class

Use of plugin system functions

The plugin system functions have been replaced with better methods of doing the same thing.

  • PluginEnabled() is replaced with an OOP-style call to the script in question's WriteSettingsEntry function.
  • PluginEnabled <prefix>, <enabled>
    

    becomes

    GetScriptByName(<name>).WriteSettingsEntry "Enabled", <enabled>
    
  • GetPluginEnabled() is replaced with an OOP-style call to the script in question's IsEnabled function.
  • <enabled> = GetPluginEnabled(<prefix>)
    

    becomes

    <enabled> = GetScriptByName(<name>).IsEnabled()
    
  • TimerInterval(), GetTimerInterval(), TimerEnabled(), GetTimerEnabled(), TimeLeft(), GetTimeLeft(), and GetTimerWaiting() all are replaced by the usage of the CreateObj function to create a long script timer.
  • TimerInterval <prefix>, <timername>, <interval>
    TimerEnabled <prefix>, <timername>, <enabled>
    

    becomes

    CreateObj "LongTimer", "<timername>"
    With <timername>
        .Interval = <interval>
        .Enabled = <enabled>
    End With
    
    If GetTimerEnabled(<prefix>, <timername>) Then
        ' ...
    End If
    

    becomes

    If <timername>.Enabled Then
        ' ...
    End If
    

    Remember:

    Sub <prefix>_<timername>_Timer()
    

    becomes:

    Sub <timername>_Timer()
    

See also