how to run code when plugin is loaded?

related to programming for xlobby, code samples, examples etc.

how to run code when plugin is loaded?

Postby damage on Wed Dec 03, 2008 8:08 pm

*i moved this into the developers forum from the generic plugin forum*

i'm writing a plugin and it needs to have a piece of code executed right after the plugin is loaded (ie is there an xplugin call that will do this?) is there any way to do this and if so, what is the syntax? thanks!
damage
 
Posts: 35
Joined: Fri Aug 18, 2006 7:07 pm

Re: how to run code when plugin is loaded?

Postby lar282 on Wed Dec 03, 2008 8:37 pm

the public xxx () will execute when the plugin starts. Or do u mean after 10 sec after the plugin loads? then u need a timer and start the timer in the start!


public class XPowerPlugin : XPlugin
{

public XPowerPlugin()
{
code that executes when the plugin starts
}


}


Does any of this make sense -:)
lar282
 
Posts: 1624
Joined: Thu Apr 01, 2004 4:13 pm
Location: Helsingborg, Sweden

Re: how to run code when plugin is loaded?

Postby damage on Wed Dec 03, 2008 8:46 pm

so you create a function inside your class and name it the same as your class? didn't seem to work for me. i'm in vb though.

Code: Select all
    Public Class xL
        Implements XPlugin

        Public Sub xL()
            InitStuff()
        End Sub
   End Class


i did a quick sample in c# and sure enough it works. i must have the vb syntax wrong?
damage
 
Posts: 35
Joined: Fri Aug 18, 2006 7:07 pm

Re: how to run code when plugin is loaded?

Postby P3rv3rt B3ar on Thu Dec 04, 2008 3:15 am

function (actually method if we stick to OO-lingo) of same name is the way constructor is noted in c++ and sharp syntax. That is method which gets called whenever instance of the class (object) is created, just find out which is notation for constructor in your language of choige, if it even has OO-features (havent touch basic since 80s).

if i remember right in practise constructor gets called when plugin is loaded during the splash screen... remember thought if u plan to set a timer or do some heavy computation u better start a new thread otherwise ull be hogging and if i remember correctly blocking XL start up... note though if u want to access XL's files, u need to block til u r done with them or wait til XL is done with them otherwise ull end up with locking probs.

now if u want to wait to the exact moment XL starts... thats extremely hard... there are some tricks u can do but still timing will be sometimes blink of an eye off. I experiment with this quite a little while trying to hijack the splash.
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Re: how to run code when plugin is loaded?

Postby damage on Thu Dec 04, 2008 4:56 am

thanks! that clears it up. this is what i did:

Public sub New()
initStuff()
end Sub
damage
 
Posts: 35
Joined: Fri Aug 18, 2006 7:07 pm