Lua programming question

  • #1, z nmvhFriday, 24. June 2022, 07:30 hodinky 2 years ago
    Here's a question for the programmers. 

    Suppose I'm designing this simple puzzle, where a retangular grid of stone bricks must be manipulated by the player. There is one brick missing, and the player can always slide one of the bricks adjacent to the "empty brick space" into that space. In that way, the bricks can be moved around, until, for example, an image appears when the bricks are in their right place.
    I'm sure most of you have encountered this kind of puzzle, either in an adventure game or (as in my case) as a physical toy.

    When I start to design the puzzle in visionaire I find myself facing several hard decisisions. That's why any input from more experienced people is welcome.

    1) Can I augment the "brick objects" (which are technically just tables in Lua, right?) with, fow example, xPosition and yPosition (in the brick grid they belong to)?

    2) How should I store the info on where every brick is located, as well as the empty space?

    3) How ould I write the code so that much of the functions are reusable, as I'm having maybe 10-30 of these puzzles throughout the game?

    I realize there is no one correct answer. I guess what I'm asking is simply "how would you have done it?"

    Bažant

    38 Posts


  • #2, z afrlmeFriday, 24. June 2022, 15:48 hodinky 2 years ago
    I haven't read your post, but I've already created & shared a template & tutorial ages ago for the dreaded sliding puzzles that everyone hates. You can find it here.

    Imperátor

    7285 Posts

  • #3, z nmvhFriday, 24. June 2022, 17:37 hodinky 2 years ago
    Too good to be true! smile Thanks a lot!!!

    Bažant

    38 Posts