lemmikens Posted November 9, 2018 Share Posted November 9, 2018 Hi there, I want to return a variable from inside the "Create()" function and use it inside of the "Update()" function. This is kind of a two part question. First of all, how would I use the variable updateStart below in the Phaser "Update()" function? It seems that even when I make it global, that startUpdate never gets set when it's inside of a function. Secondly, my game has to do with player movement after the create function after that updateStart function is set. Is the right way to go about it? Any suggestions would be greatly appreciated. This is only part of my "create()" function, by the way. I truncated a lot of it for readability. Thanks! function create(){ this.input.on('drop', function (pointer, gameObject, dropZone) { gameObject.x = dropZone.x; gameObject.y = dropZone.y-65; setXY = [dropZone.x, dropZone.y]; console.log("x = " + dropZone.x + ", y = " + dropZone.y); dropZone.clearTint(); //makes it so 'mans' can still receive input after drop gameObject.input.enabled = true; clickButton .setInteractive() .on('pointerdown', function(pointer){ locked_in = this.add.image(400,400,'locked_in'); startSpots.clear(true, true); gameObject.input.enabled = false; tween = this.tweens.add({ targets: locked_in, x: 400, // '+=100' y: 300, // '+=100' ease: 'Elastic.easeInOut', // 'Cubic', 'Elastic', 'Bounce', 'Back' duration: 2500, repeat: 0, // -1: infinity yoyo: false, alpha: { getStart: () => 1.0, getEnd: () => 0 }, onComplete: () => { } }); clickButton.destroy(); clickButton.disableInteractive(); updateStart = true; }.bind(this)); }.bind(this)); } function update (updateStart) { console.log('update'); if (updateStart == true) { console.log('bleh'); } } Link to comment Share on other sites More sharing options...
PatrickP Posted November 10, 2018 Share Posted November 10, 2018 Change updateStart in both create and update to. this.updateStart You can also remove updateStart from the update argument. Doing this.variable will declare a variable that can be used in any of the functions for that scene. lemmikens 1 Link to comment Share on other sites More sharing options...
Recommended Posts