Nikos123 Posted December 28, 2015 Share Posted December 28, 2015 Hi, I can execute local functions fine but when I do a pick on the scene there is not a way to access the objects that are siblings to the mesh like this.isSelected.Is the best way to solve this to add the parent class as a new property on the mesh, ie doing: constructor(scene, isOwn, isSelected = false) { this.mesh = BABYLON.Mesh.CreateSphere("sphere1", 8, Common.MEDIUM_UNIT_SIZE, scene); this.mesh.parentClass = this;Then I can access the parentClass from the mesh object. Will this work/is it a good idea? Quote Link to comment Share on other sites More sharing options...
RaananW Posted December 28, 2015 Share Posted December 28, 2015 Oh, I like this comment:https://github.com/QuantumInformation/Density-Wars/blob/master/lib/gameUnits/Core.ts#L12 I think you should first understand TypeScript a bit better in order to fix most of the functions in your class.I am not sure what you expect to get from "this.select". It is nowhere to be found. self = this is a javascript hack. In ES6 / TypeScript you can use arrow functions, which define the context of the function as its parent context. so:select(e:ActionEvent) { self.isSelected = true; e.meshUnderPointer.showBoundingBox = true; }could be:select = (e:ActionEvent) => { this.isSelected = true; e.meshUnderPointer.showBoundingBox = true; }This will however still fail, as "isSelected" is also not a member of the class.To do that you could set it as a member (just like you did with other variables) or use some typescript magic://isSelected set to private and is now a member of this classconstructor(scene, private isSelected = false) {//.....}same thing can be done with public, if you want it to be a public member. TypeScript is truly wonderful. Being a superset of JavaScript means you can simply throw some JS code at it, and it will compile. But the real magic, and where it really helps is when you use it correctly. Read about it at http://www.typescriptlang.org/Tutorial Quote Link to comment Share on other sites More sharing options...
Nikos123 Posted December 28, 2015 Author Share Posted December 28, 2015 For some reason I am having no luck with arrow functions with this so had to use bind for this method: https://github.com/QuantumInformation/Density-Wars/blob/master/lib/gameUnits/Core.ts#L65 Quote Link to comment Share on other sites More sharing options...
RaananW Posted December 28, 2015 Share Posted December 28, 2015 Try my suggestion, it will probably solve your problem. Anyhow - binding is a legitimate solution! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.