abdel

Members
  • Content Count

    9
  • Joined

  • Last visited

  1. hy, I have an array of players Id that I should pass the corresponding one to a function when I click on a sprite. create () { var players = [123, 234, 222, 333]; var playButs = []; for (var i = 0; i < 4; i++) { playButs.push(null); } for (i = 0; i < 4; i++) { playButs[i] = this.add.sprite(70, 10*i+20, 'sheet', 'arrow'); playButs[i].setScale(1); playButs[i].setOrigin(0); playerId = players[i]; playButs[i].setInteractive().on('pointerdown', function(){this._play(playerId)}, this); } } _play(playerId){ console.log("PlayId After: "+playerId); //Always show 333 } the is that when I click on sprite the _play function get always the last item of players array instead on corresponding player. thank you
  2. Hy, My game is just reviewed on Facebook instant game here is the link: https://fb.gg/play/switchcolors everyone here is invited to test it, and very welcomed to comment it. mainly it’s a Solo game with fiew social implementations like sharing, inviting. I’m currently looking up for 1V1 playing mode. thanks to @Noel @b10b your names are included in my credits page your help was very helpful for me.
  3. Hy and thank you I solved the issue with .bind(); I saw it from http://www.html5gamedevs.com/topic/38042-leaderboard-no-open/?tab=comments#comment-217099 And so for my case there is the code: FBInstant.player .getDataAsync(['coins']) .then(this.setPlayerData.bind(this)); and within my class: setPlayerData(data){ this.coinsVal.setText(data.coins.toString()); } and all works with magic. I posted it for anyone encounter the same problem. Thank You very much
  4. Hy again after getting mu hands dirty here I can't make it done, here is my scripts and the associated log: ---------Menu.js-------- var player = {_coinsVal: 0}; class Menu extends Phaser.Scene { constructor () { super('Menu'); } create () { console.log(1+player._coinsVal.toString()); FBInstant.player .getDataAsync(['coins']) .then(function(data) { console.log(2+player._coinsVal.toString()); player._coinsVal = 2; setPlayerData(data); console.log(3+player._coinsVal.toString()); }); console.log(4+player._coinsVal.toString()); this.coinsVal = this.add.text(70, 150, '', styleCoinsStars); } }; function setPlayerData(data){ console.log('FooBar'); console.log(data); } //Console.log Messages and comments: 10 //console.log(1+player._coinsVal.toString()); 40 //console.log(4+player._coinsVal.toString()); 20 //console.log(2+player._coinsVal.toString()); FooBar //setPlayerData(data); {coins: 0} //setPlayerData(data); 32 //console.log(3+player._coinsVal.toString()); Until here everything is like is expected no problem But when I introduce this.vars or this.funcs() the script is blocked here is an example: ---------Menu.js-------- var player = {_coinsVal: 0}; class Menu extends Phaser.Scene { constructor () { super('Menu'); } create () { console.log(1+player._coinsVal.toString()); FBInstant.player .getDataAsync(['coins']) .then(function(data) { console.log(2+player._coinsVal.toString()); player._coinsVal = 2; this.coinsVal.setText('1203'); //OR //this.coinsVal.setText(player._coinsVal.toString()); //OR EVEN //this.setPlayerData(data); //When setPlayerData is declared inside the class. setPlayerData(data); console.log(3+player._coinsVal.toString()); }); console.log(4+player._coinsVal.toString()); this.coinsVal = this.add.text(70, 150, '', styleCoinsStars); } }; function setPlayerData(data){ console.log('FooBar'); console.log(data); } //Console.log Messages & Comments: 10 //console.log(1+player._coinsVal.toString()); 40 //console.log(4+player._coinsVal.toString()); 20 //console.log(2+player._coinsVal.toString()); Here we can see that after the line this.coinsVal.setText('1203'); everything is blocked and don't executed my first impression was is that this. is not the same within FBInstant.player.getDataAsync(['coins']).then but when I log it I found that is WIndow Object. The script did not show any error or warning even if I write a wrong function like this.coinsVal.seext('1203'); it don't show any error on that also. I'm completely against the wall. Thank you for helping me.
  5. Hy and tx for you guys @b10b & @Noel I will give a try to the snipset. Tx very much.
  6. Hello guys, The perpose is that I would to get my custom data lets tell its the coins for the active player on FB instant game. From the docs I did: FBInstant.player.getDataAsync(['coins']) .then(function(data) { console.log('data is loaded'); var coins = data['coins']; }); But when I want to set my texts like: this.coinsText.setText(coins); I got an error. // coins is undefined. So I think that I did not understand the concept of PROMISE in javascript that FB uses. There is someone who can explain me the concept a snipset is very welcome just to understand. Thanks very much.
  7. Tx for your reply @Noel I will check this.
  8. Hy guys, I would like to create a FB instant game in which player can play against others rondomly. I already made the all the screens + single mode and all that works fine. But for multiplayer I can't attchieve that, I didn't found the starting point, I read the documentation from FB but not helping. Anyone can suggest me any starting point to achieve this ? My conf is: Phaser 3. Godaddy shared space with domain name. Thanks a lot