Best method for getting information (not a property) from another game object?

I’m currently working on a project where I have a game board similar to a match-3 style game. I have 2 scripts right now: game.script and board.script.

game.script - handles all things related to gameplay and validating the players input and managing what to do with the data

board.script - essentially handles the gameboard itself and is essentially a data structure for it. game.script posts messages to the board.script to tell it what to do.

The problem I’m having is I’m trying to do something along the lines of determining whether a boardspot is a valid one for the player to do an action upon. I’m getting input in my game.script, but essentially I’m trying to do a IsValid(x, y) function onto the board.script and get the value back into the game.script.

What is the best method for this, or am I completely doing this the wrong way?

A couple of different ideas comes to mind:

  • Can’t you let the board.script acquire and validate the user input instead of game.script?
  • Or can you msg.post() any user interaction from game.script to board.script and then post the result of the board validation back (this makes it become very asynchronous, but that might be fine?)
  • Move the board data structure to a Lua module and share it between board.script and game.script

Hmm…I’ll look into the Lua module and see. I was hoping to keep the game and the board separate so that I could potentially reuse the board if I wanted to make a different type of game. (Match-3 Swap game script handles input validation differently than the line draw game.) It seems like I won’t be able to do that easily.

Is there a way for a script to wait for a msg response before continuing the rest of the script?

Thanks!

This is a design question that has been discussed several times within the King teams using Defold. I believe there are cases where it is best to use a lua module prior to scripts. Having a big grid is better off centralized (imho) as soon as you need to do all these matching checking, pathfinding etc.
This is how we did it in Blossom Blast Saga and I would personally do it again like that.

4 Likes