[Gelöst/Solved - LUA] Schieberätsel / Sliding Puzzle

  • #20, by afrlmeFriday, 14. November 2014, 17:44 7 years ago
    I use rational logic. It's everyone else that thinks illogically. I try to mentally break down how something should work (logic) & then I create based around that.

    The script slides the animation tile to the new position & swaps sliding tile name with target tile name. It also on tile (slot) click checks the move positions for the tile you clicked on by checking the index numbers we added to the move part of the table & if one of tables returns empty (nil) for the name then that means the tile can move to that slot. Pretty simple. Much easier than using millions of conditions, images & if queries to change the tiles.

    I was not very confident about being able to code this as I had nothing as a reference base & ended up having to piece together how it worked off the top of my head alone. I'm not very good at math or puzzles like this, so it was a bit of a challenge.

    & it could be my fault? I have terrible short term memory, so I probably read whatever you mentioned before but will have completely forgotten about it.


    7008 Posts

  • #21, by MachtnixFriday, 14. November 2014, 18:21 7 years ago
    I use rational logic. It's everyone else that thinks illogically. I try to mentally break down how something should work (logic) & then I create based around that.

    With "strange logic" I didn't mean illogical. It's not easy to explain. It's a "programmers logic" which correspond with the languages and the machines. F.e.: you change the tile's name and the tile's picture, not the real position of the tile. That's not the thinking in real life - it's program thinking... ;-)

    Thread Captain

    1093 Posts

  • #22, by afrlmeFriday, 14. November 2014, 18:31 7 years ago
    I did change actual position of the tile (image/animation) I made it slide to the empty tile position with easing. I only updated the name of slot that the tile was moved to. Which makes logical sense no?

    Would you like me to draw you a diagram perchance? I already created a mini-diagram on the script page explaining how I determined the allowed movement directions for each tile slot.

    Long story short we gave each tile slot the name "nil" on script load. We then shuffled the actual names which I added inside of another table (there is simple randomize table order function so I wrote my own which involved removing the end table entry & randomly placing it back into the table a few times), then the newly shuffled list name was added into the tile slot table from slot 1-8 which meant slots 1-8 now had tiles in random order while leaving slot 9 as empty.

    & even longer story short: I did do what you would do in real-life version of the puzzle. I moved the tiles position, but I just also happened to swap the slot names too.

    From a logical (real perspective) how would you have done it? or how do you think it should have worked? I'm quite interested in knowing.

    * edit: There was an alternative method I could have used which involved the move object action part or lua function but the problem with that method is that it uses offset & not direct positioning which is somewhat confusing. That method however would have moved the object polygon with the image too which means we wouldn't have had to check/update the tile names. We would have just had to check against current position against positions it could potentially move to. But either way involved complicated scripting.


    7008 Posts