• 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 toString returns [object Object]

Pheeko

Active Member
Hey,
Can someone tell me why toString() helper function returns [object Object] instead of a string representation of an object?
Here's the code:
engine.log(ev.toString());
I also tried:
engine.log(toString(ev));

var helpers = require('helpers');
engine.log(helpers.toString());

However helpers.toString() returns empty string.

Thanks in advance.
 

Pheeko

Active Member
I'm trying to convert event to json when it's getting triggered then send it to webserver.
Here's the code:
JavaScript:
config.events.forEach(function (e){
      if(e.active){
        event.on(translateEvent(e.event_name), function(ev){
          if (ev.client.isSelf()) {
              return;
          }
          engine.log(ev.toString());
          var params = "data="+helpers.toString(ev);
          sinusbot.http({
          method:     'POST',
          url:        e.url,
          timeout:    6000,
          headers:    {
              "Content-Type": "application/x-www-form-urlencoded",
          },
          body: params
      }, function(error, response) {
          engine.log(response);
      });
        });
      }
    });
 

r3flex

Active Member
Contributor
well you cant stringify object, you have do make iteration through set of objects or access one by its name and then parameters.
You could also convert an object to array.
 

Pheeko

Active Member
I tried stringify but it doesn't return client and channel object intead i get this: {"channel":{},"client":{},"mode":1,"text":"msg"}
 

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
well you cant stringify object, you have do make iteration through set of objects or access one by its name and then parameters.
You could also convert an object to array.
Nope, you can stringify an object, some classes don't work though.
 

mxschmitt

Moderator
Staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
I tried stringify but it doesn't return client and channel object intead i get this: {"channel":{},"client":{},"mode":1,"text":"msg"}
That's normal, because client is a "class" with methods in it which returns the data. What data of the event do you need exactly?
 

Pheeko

Active Member
Also when I engine.log(ev) it displays all the fields in the console. So why is it not possible to stringify this?
 

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Also when I engine.log(ev) it displays all the fields in the console. So why is it not possible to stringify this?
Because javascript works like that and engine.log is not handled by javascript.
 
Top