2
Say I want to do a function debugText(obj)
, this function takes an object as a parameter and shows a property of it on the screen, such as debug game screens.
Something like:
function debugText(link,prop) { this.TextObject = new Engine.Utils.Text() this.link = link this.prop = prop this.update = function () { this.TextObject.setText( this.link[this.prop] ) } }
In use:
var texto1 = new debugText(Player,"speedX") var texto2 = new debugText(Missle,"positionY")
It works great for these two examples and when I need to know other things when testing the code, more if I want to access something like:
Player.skin.currentAnimation.frame.frameInfo.index
?
I could add more parameters to the function and then see how many of them are being used and create the this.update
based on that.
However this function will always be limited there is a fixed number of properties and even if I will never use more than 5 I still do not like how this function works: http://pastebin.com/WT6VYE5
EDIT
The question is: has a correct means of "mirroring" the properties of an object or updating them with a Function call independent of how many depth levels Object.prop1.prop2.pro3...
that has to update?
For you to know how many ways I’ve thought of how to do this is the last
debugText(Player.skin.currentAnimation.frame.frameInfo,"index")
This also works BUT it really is certain to pass an object with the properties and pass only the last property as string only to use the computed Property Names to access this value?
I can’t use the console.log() because sometimes I have to show more than 5 things with updated values once per frame and this besides flodar the conosole, ends up lagging a little. Now JSON.stringfy really can help me in this case. Thanks man, it would take a long time to think about it.
– Mendes