This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
fireair's profile picture

I'd like to make a sliding puzzle lock.

Started by fireair, 30 March 2018 - 04:43 PM
fireair #1
Posted 30 March 2018 - 06:43 PM
Ok so here's what I'm trying to do, I want a monitor based puzzle where you right click a monitor and if there is an empty monitor adjacent to the one you clicked it will send the text from the monitor you clicked to the one that's empty, then when all the pieces are in the correct spot it sends a redstone signal out of the left side of the computer to open a door. Here is my problem, i have no idea if this can even be done ihave a scrolling text program (https://pastebin.com/YYK0dQED) but im not sure where to go from there. Help would be greatly appreciated.
Bomb Bloke #2
Posted 31 March 2018 - 05:38 AM
You can put tables inside tables:

local tText = {
		{
			{"top left corner of the image"}, {"top right corner of the image"},
		},
		
		{
			{"bottom left corner of the image"}, {"bottom right corner of the image"}
		}
	}

Obviously you'd want more segments than that, but you get the idea. In the example above, the top right segment would be referred to as tText[1][2], and the bottom left segment would be tText[2][1].

If you knocked out the bottom right corner (tText[#tText][#tText[1]] = nil), and then ran a loop for a few hundred iterations which picks random tiles and swaps them, then it'd just be a matter of running a loop that detects mouse clicks and determines which tile was clicked on. If the empty (nil) tile is next to it, then swap, and repeat until all tiles are back where they're supposed to be.

Forget about making the tiles go through any sort of sliding animation for now - start out by simply instantly redrawing the moved tiles in their new positions, and then worry about the cosmetics when the basic game is functional.
fireair #3
Posted 01 April 2018 - 07:17 PM
Ok thanks