nak3ddogs Posted July 19, 2014 Share Posted July 19, 2014 helo. i work on my first project with stage managment. Im littlebit confused coz when i make a function, in the function the 'this' is not a reference for the Basicgame.Mainmenu.usually i use argument for get it. like this: func(this); func: function(place){ console.log(place);} but now i have to use my function on multiple place. and somewhere i cant use argument for it. how can i get the absolute path to Basicgame.MainMenu stage?i tryed basicgame.mainmenu but it is just a function. and not same when i use 'this' in the mainmenu. sry for my english and thx for any advice Link to comment Share on other sites More sharing options...
lewster32 Posted July 19, 2014 Share Posted July 19, 2014 A sample of your code with the problem line highlighted would help us determine the correct context for you. Link to comment Share on other sites More sharing options...
Dumtard Posted July 19, 2014 Share Posted July 19, 2014 This is most likely a problem with the way you are structuring your code. As lewster32 said, would be easier to see the code of where the function is located and where you are calling it from to know the correct context.And please us the code tag when pasting code as it is much easier to read and follow. Link to comment Share on other sites More sharing options...
nak3ddogs Posted July 19, 2014 Author Share Posted July 19, 2014 i solved my problem. but i dont understand already.how can i get basicgame.mainstage object when i write a console.log(this) in the BasicGame.MainMenu = function (game) { console.log(this) // its print out BasicGame.MainMenu {}},but when im in deep one of the function and would use 'this'its not point to BasicGame.MainMenu {} my only js knowledge from the codeacademy. but its far not enought before i started use the stages i could use the game variable to point of stage. game.add.sprite.... but now i have to use this.add.sprite i tryed to use thisBasicGame.MainMenu.add.sprite... but it wont work Link to comment Share on other sites More sharing options...
lewster32 Posted July 19, 2014 Share Posted July 19, 2014 When using states, 'this' inside the functions defined in the state is populated with some values; this.game being the important one. I think if you look at the following sample project's main 'Game' state, you can see how to structure your game and how to access various items: https://github.com/photonstorm/phaser-examples/blob/master/projects/bomber/src/Game.js Scope is a tricky beast, and the myriad ways of writing JavaScript makes it all the more tricky. Stick with it though, you'll figure it out soon enough! nak3ddogs 1 Link to comment Share on other sites More sharing options...
nak3ddogs Posted July 19, 2014 Author Share Posted July 19, 2014 i respect . without u i given up Link to comment Share on other sites More sharing options...
Recommended Posts