• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

EN Using new api "Classes"

Status
Not open for further replies.

Ofir Gal

Member
Hey, which is more efficient?

PHP:
registerPlugin....

var engine = require('engine');

sinusbot.on('chat', function(ev) {
    engine.log('Hello from a script!');
});

sinusbot.on('poke', function(ev) {
        engine.log('We got poked by ' + ev.clientNick + ': ' + ev.msg);
});

or

PHP:
registerPlugin....

sinusbot.on('chat', function(ev) {
    var engine = require('engine');
    engine.log('Hello from a script!');
});

sinusbot.on('poke', function(ev) {
     var engine = require('engine');
     engine.log('We got poked by ' + ev.clientNick + ': ' + ev.msg);
});
 
i would recommend to use the first solution, they both do the same but with the first you are much cleaner and need to write less
But the Second Solution probably does not even use more Ram

You could even do
require('ENGINE').log("bla")
 
The first one, but I think it doesn't really matter a lot in that particular case. You should however use the new event module as well.
 
Thx for the quick answers, I have just wondered if its waste of memory

We are not in C/C++ here, so we don't need to think much about Memory Leeking. Behind the Engine runs a Garbage Collector, so mostly the memory should be clean :p


But +1 for the interest in writing clean code.
 
Last edited:
Status
Not open for further replies.
Back
Top Bottom