Entire code is in function create, not function update

Hi, the structure of my entire board game code below summarized. I don’t know how to move sections of it to function update(){}

   var game = new Phaser.Game(config);


       //Game variables, buttons, texs, arrays etc
        activePlayer = player1;
        function Assets1{
        	//code
        };
        function Assets2{
     	//code
        };
        
        function preload() {
	//Load spritesheets, images
        }


        function create() {
            //Code to add spritesheets, images

            function switchTurns1() {
            //Code
            };

            function switchTurns2() {
            //code
            };
	//example code below for player 1 (summarized)
            let popup1 = this.add.image(680, 300, 'popup'); //popup to buy asset for player 1
            let yesButton1 = this.add.image(popup1.x - 50, popup1.y + 60, 'yes-up');//yes to buy asset player1
            let noButton1 = this.add.image(popup1.x + 50, popup1.y + 60, 'no-up');// no to buy asset player 1
            yesButton1.setInteractive();
            popup1.visible = false;
            noButton1.visible = false;
            yesButton1.visible = false;

            //Roll dice for player 1
            diceButton1.on('pointerup', function () {
                if (activePlayer !== player1) return;
                diceButton1.visible = false; // Hide dice 1 
                movePlayer1.visible = true; //Show move player1

                //Add cash for passing start
                //Change player position on board
                //Move player1 to pixel position on board

                movePlayer1.on('pointerup', function () {
                    this.tweens.add({
                        targets: woman,
                        x: playerPixelPosition[player1.position][0],
                        y: playerPixelPosition[player1.position][1],
                        duration: 1000
                    });

                    //  Landing on special cases
                    switch (ASSETS[player1.position][0]) {
                        case "START": 
                            //code here
                            break;                             
                        case "Bett-on Bets":
                            //Randomly select betting option from betting array
                            //Variables defining popup for  betting are declared here
                            yesButton.on('pointerdown', function() {
			    //Code to ay based of outcome of dice roll
                                if (dice1===dice2){
				//code
                                }
                                else{
				//code
                                };
			    //code
                                switchTurns1();
                            });
                            noButton.on('pointerdown', function() {
                                //code
                                switchTurns1();
                            });
                            break;
                        default:
                            // Code for Player 1 purchase asset            
                            //Code for opponent already own the asset? Process payment
                       	//Code for player already owns the asset
			//Code for player does  not have enough money to buy the asset
                                break;
                            }
                    }
                }, this);
            }, this);
            //Code to compute networth1 value for player 1

            //Roll dice for player 2
            //Repeat example code for player 1
        }        
        
        function update() {
        }

Can you please provide more context on the code that you want in the update function? From the code you shared above, it looks like most of your existing logic is based on a player interaction, and might not need to go in the update method.

I wasn’t sure if the game will need to go into the update function. Everything is working fine in the create function except for this section. There’s a roll dice button inside function create. Inside the code within the roll dice button is a switch statement. In the switch case I need to generate a popup window for user response. The popup button displays a message pulled randomly from an array within the switch case. If the popup window is created within the switch case, it gets recreated every time on top of the previous one and gives me problems. However, If I move it out of the switch case directly into create function, the popup works but the message generated within the switch case is not displayed with the popup. The section of the code is below with arrows pointing towards the message variable for easy identification. Thanks.

function create() {
//popup for betting
===> let message1
let betPopup = this.add.image(800, 300, ‘betpopup’);// player1 betting popup
let messageText = this.add.text(betPopup.x, betPopup.y - 30, message1, {font: ‘20px Arial’, fill: ‘#000000’});//betting message player1
messageText.setOrigin(0.5, 0.5);
let yesButton = this.add.image(betPopup.x - 50, betPopup.y + 20, ‘betdice’);
let noButton = this.add.image(betPopup.x + 50, betPopup.y + 20, ‘no-up’);
yesButton.setInteractive();
noButton.setInteractive();
betPopup.visible = false;
noButton.visible = false;
yesButton.visible = false;
messageText.visible = false;

	//Roll dice for player 1
            diceButton1.on('pointerup', function () {
                if (activePlayer !== player1) return;
                diceButton1.visible = false; 
                movePlayer1.visible = true; 
    
                let dice1 = Math.floor(Math.random() * 6) + 1;
                let dice2 = Math.floor(Math.random() * 6) + 1;
                let dice3 = dice1 + dice2;
                diceText.setText(dice1 + ' X ' + dice2);
    
		//Change player position
                	if (player1.position > 41) {
                    player1.position = player1.position - 42;      
                	}

                playerText.setText(ASSETS[player1.position][0] + " (N" + ASSETS[player1.position][1].assetCost + ")") //Displays the name of the asset at that position
        
                	//Move player1 to pixel position on board

                	movePlayer1.on('pointerup', function () {
                    this.tweens.add({
                        targets: woman,
                        x: playerPixelPosition[player1.position][0],
                        y: playerPixelPosition[player1.position][1],
                        duration: 1000
                    });
		//  Landing on special cases
                    switch (ASSETS[player1.position][0]) {

			//Missing code goes here
			case "Bett-on Bets":
			//Randomly select betting option from betting array
                            let betting = [["Will you like to bet N1M to get N2M",1000000, 2000000],
                                    ["Will you like to bet N3M to get N6M",3000000, 6000000],
                                    ["Will you like to bet N5M to get N12M",5000000, 12000000],
                                    ["Will you like to bet N20M to get N50M",20000000, 50000000]
                                ]                                
                            let randomBetStore = [0]
                            let randomBets = Math.floor(Math.random() * betting.length);
                            randomBetStore.unshift(randomBets)    
===>                        message1 = betting[randomBetStore[0]][0];

                            betPopup.visible = true;
                            noButton.visible = true;
                            yesButton.visible = true;
                            messageText.visible = true;
                            yesButton.on('pointerdown', function() {
                                let dice1 = Math.floor(Math.random() * 6) + 1;
                                let dice2 = Math.floor(Math.random() * 6) + 1;
                                diceText.setText(dice1 + ' X ' + dice2);
                                //pay based of outcome of dice roll
                                if (dice1===dice2){
                                    player1.money += betting[randomBetStore[0]][2];
                                    playerCommentaryText.setText ("You just received  N" + betting[randomBetStore[0]][2]);
                                    player1MoneyText.setText("N" + player1.money);
                                }
                                else{
                                    player1.money -= betting[randomBetStore[0]][1];
                                    playerCommentaryText.setText ("You just lost  N" + betting[randomBetStore[0]][1]);
                                    player1MoneyText.setText("N" + player1.money);
                                    };
                                betPopup.visible = false;
                                noButton.visible = false;
                                yesButton.visible = false;
                                messageText.visible = false;
                                switchTurns1();
                            });
                            
                            noButton.on('pointerdown', function() {
                                betPopup.visible = false;
                                noButton.visible = false;
                                yesButton.visible = false;
                                messageText.visible = false;                                    
                                playerCommentaryText.setText ("No problem, your money is intact");
                                switchTurns1();
                            });
};

};

Thanks for the additional details. After you update your message1 variable, you will need to update the text of the Phaser Text GameObject. You can do this by using the setText method on the messageText variable, and you will just want to pass in your message1.

More information on that method can be found here: Phaser 3 API Documentation - Class: Text

Thanks, resolved