Dumping Object Info to the Console
graver

Is there a way to dump/print an objects information to the console or something else that is human readable?

For-instance, if I have the fallowing lines of code:

var flag = wade.getSceneObject('moveflag');

wade.iso.moveObjectToTile(flag,1,1);

Is there any way to print out the full contents of the variable "flag"?

So far, the best I can do is either use "console.log(flag)" or "console.log(flag.some_property_to_show_that_it_is_object_moveflag)". The first will just print out "[object Object]" which at least tells me it is defined and the second will give me what ever property i set which I would think tells me the right object is being referenced. However, that doesn't seem to be enough because something is going wrong and those methods aren't telling me what.

Like when using the above 2 lines of code; in a behavior I'm working on, I get the fallowing error after almost every other moveObjectToTile function call:

Uncaught TypeError: Cannot read property 'object' of undefined (isoCharacter.js, 378:39)

Literally, the function call only works about half of the time. It goes off without a hitch the first time, fails the second time, works the third, fails the forth, works the fifth, sometimes the sixth but usually not, definitely the seventh, maybe the eighth...etc. It's weird. If it always failed, it'd be easier to figure out but this sometimes working, sometimes not is confusing me. I figure, if there was a way i could get more info about the, well, info being passed to the function, i might stand a better chance of figuring out what i did wrong.

Anyway, thanks all!

 

 

All 2 Comments
Gio

Hi

There are a few ways to go about this. The first one would be to just output the object data in WADE's console - to do this, while the game is running in the preview, type something like _.moveflag under the preview window (where it says "Write some code here..."). This will output a JSON representation of the object in the logs. Click the line above it (the line that just turned green) to open the logs and look at it.

Alternatively, and this is probably better, while running your game make sure that you have Chrome's developer tools open (F12). Go to the Sources tab, look in the top right, and make sure that you have a blue button to pause on exceptions, and also that "Pause on caught exceptions" is unchecked, as in this picture

This will make Chrome stop the execution of your app when that error happens. From there you can debug using Chrome's debugger to see what's wrong with your code.

I hope this helps

graver

Thank you for telling me about chrome's debugger! I had no idea that existed and it has definitely helped me find the root of this problem. The root, however, is another odd problem.

Apparently, I screwed up how an object's property is forever read. I had initially decided to make a certain property store true/false but latter changed it so it would store numerical values that would be incremented every time the object entered a new tile. The code still wants to treat the value as true/false leading to a situation where it would be read before incrementing as "true". That threw everything completely off since, instead of going 0, 1, 2, 3 it went true, 2, 3, 4.

Weirdly enough, it will now read any value it starts off with as "true": 1 is true, 0 is true, -1 is true, false is true...

Post a reply
Add Attachment
Submit Reply
Login to Reply