Adding Game Over Message with data from MongoDB

Hey everybody,

totally new to phaser and just finished the intro tutorial here. I combined it with this tutorial on how to implement a message modal here.

I’m now calling the dialog modal “on Game Over” of the tutorial game. The dialog modal is created as a plugin in an external file and called with an “init” function. The code is working so far, but I would like to know how I might implement a call to a mongoDB Atlas connection.

I have the phaser game running on localhost via an express server. I have a successful connection to mongoDB Atlas running in the express app and can find / serve mongoDB objects.

I would like to be able to make a call to the DB collection and display the message from DB in my message modal. The idea is to show a quiz question, which allows the player to prolong their game.

Right now I’m unsure how to execute an async await function within the constructor of the dialog modal. Whenever I introduce async, the game fails on me. Do you have any ideas or resources? I would really appreciate it.

Thank You!

TL;DR:

  • Running phaser 3 tutorial game via express server
  • I have a good connection to a mongoDB Atlas collection using mongoose
  • I am calling a message modal “on Game Over” of the tutorial game
  • I would like to fill the message modal with a quiz question from mongoDB
  • Whenever I try to implement async functions, the game fails on me
  • I am looking for direct support or resources, if you can help

Thanks!

Why would you put the async in the dialog?
Create the dialog once, use setText after you’ve retrieved your question, and open the dialog.