<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.atitd.org/wiki/t6w/index.php?action=history&amp;feed=atom&amp;title=User%3APheros%2Fthistle_multi</id>
	<title>User:Pheros/thistle multi - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://www.atitd.org/wiki/t6w/index.php?action=history&amp;feed=atom&amp;title=User%3APheros%2Fthistle_multi"/>
	<link rel="alternate" type="text/html" href="http://www.atitd.org/wiki/t6w/index.php?title=User:Pheros/thistle_multi&amp;action=history"/>
	<updated>2026-06-07T22:18:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>http://www.atitd.org/wiki/t6w/index.php?title=User:Pheros/thistle_multi&amp;diff=178852&amp;oldid=prev</id>
		<title>Pheros: Created page with &quot;harvest 32 gardens pinned with window arranger  &lt;pre&gt;  -- -- To run: --  Copy a recipe from the output of the Thistle Mode --  Update expected_gardens equal to the number you hav...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.atitd.org/wiki/t6w/index.php?title=User:Pheros/thistle_multi&amp;diff=178852&amp;oldid=prev"/>
		<updated>2012-04-03T01:50:05Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;harvest 32 gardens pinned with window arranger  &amp;lt;pre&amp;gt;  -- -- To run: --  Copy a recipe from the output of the Thistle Mode --  Update expected_gardens equal to the number you hav...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;harvest 32 gardens pinned with window arranger&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
--&lt;br /&gt;
-- To run:&lt;br /&gt;
--  Copy a recipe from the output of the Thistle Mode&lt;br /&gt;
--  Update expected_gardens equal to the number you have opened and pinned&lt;br /&gt;
--    Gardens must all have their buttons visible, can overlap as long as the&lt;br /&gt;
--    row with &amp;quot;asc&amp;quot; is visible regardlesss of which window was clicked last&lt;br /&gt;
--  Update &amp;quot;last sun&amp;quot; to be what it is now (0 if night,&lt;br /&gt;
--    99 if daylight and open lid, 33 if daylight and closed lid)&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
loadfile(&amp;quot;luaScripts/screen_reader_common.inc&amp;quot;)();&lt;br /&gt;
loadfile(&amp;quot;luaScripts/ui_utils.inc&amp;quot;)();&lt;br /&gt;
&lt;br /&gt;
per_click_delay = 0;&lt;br /&gt;
&lt;br /&gt;
local expected_gardens = 32;&lt;br /&gt;
local last_sun = 33;&lt;br /&gt;
&lt;br /&gt;
instructions = {&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,1,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,1,1,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,2,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,2,0,0,&lt;br /&gt;
0,0,0,3,0,&lt;br /&gt;
0,0,1,1,0,&lt;br /&gt;
0,0,1,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,1,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,1,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,2,0,&lt;br /&gt;
0,0,1,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local window_locs = {};&lt;br /&gt;
&lt;br /&gt;
function setWaitSpot(x0, y0)&lt;br /&gt;
	setWaitSpot_x = x0;&lt;br /&gt;
	setWaitSpot_y = y0;&lt;br /&gt;
	setWaitSpot_px = srReadPixel(x0, y0);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function waitForChange()&lt;br /&gt;
	local c=0;&lt;br /&gt;
	while srReadPixel(setWaitSpot_x, setWaitSpot_y) == setWaitSpot_px do&lt;br /&gt;
		lsSleep(1);&lt;br /&gt;
		c = c+1;&lt;br /&gt;
		if (lsShiftHeld() and lsControlHeld()) then&lt;br /&gt;
			error 'broke out of loop from Shift+Ctrl';&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- lsPrintln('Waited ' .. c .. 'ms for pixel to change.');&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function clickAll(image_name, up)&lt;br /&gt;
	-- Find buttons and click them!&lt;br /&gt;
	srReadScreen();&lt;br /&gt;
	xyWindowSize = srGetWindowSize();&lt;br /&gt;
	local buttons = findAllImages(image_name);&lt;br /&gt;
	&lt;br /&gt;
	if #buttons == 0 then&lt;br /&gt;
		statusScreen(&amp;quot;Could not find specified buttons...&amp;quot;);&lt;br /&gt;
		lsSleep(150);&lt;br /&gt;
	else&lt;br /&gt;
		statusScreen(&amp;quot;Clicking &amp;quot; .. #buttons .. &amp;quot;button(s)...&amp;quot;);&lt;br /&gt;
		if up then&lt;br /&gt;
			for i=#buttons, 1, -1  do&lt;br /&gt;
				srClickMouseNoMove(buttons[i][0]+5, buttons[i][1]+3);&lt;br /&gt;
				lsSleep(per_click_delay);&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			for i=1, #buttons  do&lt;br /&gt;
				srClickMouseNoMove(buttons[i][0]+5, buttons[i][1]+3);&lt;br /&gt;
				lsSleep(per_click_delay);&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		statusScreen(&amp;quot;Done clicking (&amp;quot; .. #buttons .. &amp;quot; clicks).&amp;quot;);&lt;br /&gt;
		lsSleep(100);&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function clickAllComplex(image_names, message)&lt;br /&gt;
	if not message then&lt;br /&gt;
		message = &amp;quot;&amp;quot;;&lt;br /&gt;
	end&lt;br /&gt;
	-- Find buttons and click them!&lt;br /&gt;
	srReadScreen();&lt;br /&gt;
	local dpos = {};&lt;br /&gt;
	for i=1, #image_names do&lt;br /&gt;
		local pos = srFindImageInRange(image_names[i],&lt;br /&gt;
			window_locs[#window_locs][0], window_locs[#window_locs][1],&lt;br /&gt;
			410, 312);&lt;br /&gt;
		if not pos then&lt;br /&gt;
			error ('Failed to find ' .. image_names[i]);&lt;br /&gt;
		end&lt;br /&gt;
		dpos[i] = {};&lt;br /&gt;
		dpos[i][0] = pos[0] - window_locs[#window_locs][0];&lt;br /&gt;
		dpos[i][1] = pos[1] - window_locs[#window_locs][1];&lt;br /&gt;
	end&lt;br /&gt;
	statusScreen(message .. &amp;quot; Clicking &amp;quot; .. #window_locs .. &amp;quot; button(s)...&amp;quot;);&lt;br /&gt;
	local first = 1;&lt;br /&gt;
	for i=#window_locs, 1, -1 do&lt;br /&gt;
		if not first then&lt;br /&gt;
			-- focus&lt;br /&gt;
			setWaitSpot(window_locs[i+1][0], window_locs[i+1][1]);&lt;br /&gt;
			srClickMouseNoMove(window_locs[i][0], window_locs[i][1]);&lt;br /&gt;
			waitForChange();&lt;br /&gt;
		end&lt;br /&gt;
		-- click all buttons&lt;br /&gt;
		for j=1, #image_names do&lt;br /&gt;
			srClickMouseNoMove(window_locs[i][0] + dpos[j][0] + 5, window_locs[i][1] + dpos[j][1] + 5);&lt;br /&gt;
		end&lt;br /&gt;
		first = nil;&lt;br /&gt;
	end&lt;br /&gt;
	lsSleep(100);&lt;br /&gt;
	statusScreen(message .. &amp;quot; Refocusing...&amp;quot;);&lt;br /&gt;
	-- refocus&lt;br /&gt;
	for i=2, #window_locs do&lt;br /&gt;
		setWaitSpot(window_locs[i][0], window_locs[i][1]);&lt;br /&gt;
		srClickMouseNoMove(window_locs[i][0], window_locs[i][1] + 310);&lt;br /&gt;
		waitForChange();&lt;br /&gt;
	end&lt;br /&gt;
	lsSleep(100);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
button_names = {&amp;quot;ThistleNit.png&amp;quot;, &amp;quot;ThistlePot.png&amp;quot;, &amp;quot;ThistleH2O.png&amp;quot;, &amp;quot;ThistleOxy.png&amp;quot;, &amp;quot;ThistleSun.png&amp;quot;};&lt;br /&gt;
&lt;br /&gt;
local z = 2;&lt;br /&gt;
&lt;br /&gt;
-- Initialize last_mon&lt;br /&gt;
local mon_w = 10;&lt;br /&gt;
local mon_h = 152;&lt;br /&gt;
local last_mon = {};&lt;br /&gt;
for x=1, mon_w do&lt;br /&gt;
	last_mon[x] = {};&lt;br /&gt;
	for y=1, mon_h do&lt;br /&gt;
		last_mon[x][y] = 0;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function waitForMonChange(message)&lt;br /&gt;
	if not first_nit then&lt;br /&gt;
		first_nit = srFindImage(&amp;quot;ThistleNit.png&amp;quot;);&lt;br /&gt;
	end&lt;br /&gt;
	if not first_nit then&lt;br /&gt;
		error &amp;quot;Could not find first Nit&amp;quot;;&lt;br /&gt;
	end&lt;br /&gt;
	mon_x = first_nit[0] - 25;&lt;br /&gt;
	mon_y = first_nit[1] + 13;&lt;br /&gt;
		&lt;br /&gt;
	local different = nil;&lt;br /&gt;
	local skip_next = nil;&lt;br /&gt;
	local first_loop = 1;&lt;br /&gt;
	while not different do&lt;br /&gt;
		srReadScreen();&lt;br /&gt;
		for x=1, mon_w do&lt;br /&gt;
			for y=1, mon_h do&lt;br /&gt;
				newvalue = srReadPixelFromBuffer(mon_x + x, mon_y + y);&lt;br /&gt;
				if not (newvalue == last_mon[x][y]) then&lt;br /&gt;
					different = 1;&lt;br /&gt;
				end&lt;br /&gt;
				last_mon[x][y] = newvalue;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if not different then&lt;br /&gt;
			first_loop = nil;&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		if different then&lt;br /&gt;
			-- Make sure the screen was done refreshing and update again&lt;br /&gt;
			lsSleep(60);&lt;br /&gt;
			srReadScreen();&lt;br /&gt;
			for x=1, mon_w do&lt;br /&gt;
				for y=1, mon_h do&lt;br /&gt;
					last_mon[x][y] = srReadPixelFromBuffer(mon_x + x, mon_y + y);&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		if (different and skip_next) then&lt;br /&gt;
			skip_next = nil;&lt;br /&gt;
			different = nil;&lt;br /&gt;
		end &lt;br /&gt;
		&lt;br /&gt;
		lsPrintWrapped(10, 5, 0, lsScreenX - 20, 1, 1, 0xFFFFFFff, message);&lt;br /&gt;
		lsPrintWrapped(10, 60, 0, lsScreenX - 20, 1, 1, 0xFFFFFFff, &amp;quot;Waiting for change...&amp;quot;);&lt;br /&gt;
		if lsButtonText(lsScreenX - 110, lsScreenY - 30, z, 100, 0xFFFFFFff, &amp;quot;End script&amp;quot;) then&lt;br /&gt;
			error &amp;quot;Clicked End Script button&amp;quot;;&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if lsButtonText(40, lsScreenY - 60, z, 200, 0xFFFFFFff, &amp;quot;Force tick&amp;quot;) then&lt;br /&gt;
			different = 1;&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if lsButtonText(40, lsScreenY - 90, z, 200, 0xFFFFFFff, &amp;quot;Skip tick&amp;quot;) then&lt;br /&gt;
			skip_next = 1;&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if lsButtonText(40, lsScreenY - 120, z, 200, 0xFFFFFFff, &amp;quot;Finish up&amp;quot;) then&lt;br /&gt;
			finish_up = 1;&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		-- display mon pixels&lt;br /&gt;
		for x=1, mon_w do&lt;br /&gt;
			for y=1, mon_h do&lt;br /&gt;
				local size = 2;&lt;br /&gt;
				lsDisplaySystemSprite(1, 10+x*size, 90+y*size, 0, size, size, last_mon[x][y]);&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		lsDoFrame();&lt;br /&gt;
		lsSleep(100);&lt;br /&gt;
	end&lt;br /&gt;
	statusScreen(&amp;quot;Changed, waiting a moment for other beds to catch up...&amp;quot;);&lt;br /&gt;
	if not first_loop then -- Don't wait, we might be behind already!&lt;br /&gt;
		lsSleep(150); -- Wait a moment after image changes before doing the next tick&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function test()&lt;br /&gt;
&lt;br /&gt;
	local loop=0;&lt;br /&gt;
	while 1 do&lt;br /&gt;
		waitForMonChange(&amp;quot;tick &amp;quot; .. loop);&lt;br /&gt;
		&lt;br /&gt;
		statusScreen('Changed!');&lt;br /&gt;
		lsSleep(100);&lt;br /&gt;
		loop = loop + 1;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	error 'done';&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
 function refillWater()&lt;br /&gt;
--	statusScreen(&amp;quot;Refilling water...&amp;quot;);&lt;br /&gt;
--	srClickMouseNoMove(359, 13);&lt;br /&gt;
--	lsSleep(100);&lt;br /&gt;
--	srClickMouseNoMove(srGetWindowSize()[0]/2 + 10, srGetWindowSize()[1]/2 + 20);&lt;br /&gt;
--	lsSleep(4000);&lt;br /&gt;
	lsSleep(100);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function doit()&lt;br /&gt;
	num_loops = 1;&lt;br /&gt;
	askForWindow(&amp;quot;Pin any number of thistle gardnes, edit thistle_custom with recipe.&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	if not ( #instructions == 41*5) then&lt;br /&gt;
		error 'Invalid instruction length';&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	srReadScreen();	&lt;br /&gt;
	window_locs = findAllImages(&amp;quot;ThisIs.png&amp;quot;);&lt;br /&gt;
	if not (#window_locs == expected_gardens) then&lt;br /&gt;
		error (&amp;quot;Did not find expected number of thistle gardens (found &amp;quot; .. #window_locs .. &amp;quot; expected &amp;quot; .. expected_gardens .. &amp;quot;)&amp;quot;);&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
--	wl2 = {};&lt;br /&gt;
--	wl2[1] = window_locs[31];&lt;br /&gt;
--	wl2[2] = window_locs[32];&lt;br /&gt;
--	window_locs = wl2;&lt;br /&gt;
--	if not (#window_locs == 2) then&lt;br /&gt;
--		error 'fail';&lt;br /&gt;
--	end&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	-- test();&lt;br /&gt;
	&lt;br /&gt;
	for loops=1, num_loops do&lt;br /&gt;
		&lt;br /&gt;
		-- clickAll(&amp;quot;ThisIs.png&amp;quot;, 1);&lt;br /&gt;
		-- lsSleep(100);&lt;br /&gt;
		&lt;br /&gt;
		srReadScreen();&lt;br /&gt;
		&lt;br /&gt;
		-- clickAllComplex({&amp;quot;Harvest.png&amp;quot;}, 1);&lt;br /&gt;
		-- error 'done';&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		-- clickAllComplex({&amp;quot;ThistleAbort.png&amp;quot;}, 1);&lt;br /&gt;
		-- error 'done';&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		-- statusScreen(&amp;quot;(&amp;quot; .. loops .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Doing initial 2s wait...&amp;quot;);&lt;br /&gt;
		-- lsSleep(2000);&lt;br /&gt;
		--waitForMonChange(&amp;quot;Getting initial image...&amp;quot;);&lt;br /&gt;
--		for i=0, 39 do&lt;br /&gt;
--			local to_click = {};&lt;br /&gt;
--			if (i == 0) then&lt;br /&gt;
--				to_click[1] = &amp;quot;ThistlePlantACrop.png&amp;quot;;&lt;br /&gt;
--			end&lt;br /&gt;
--			for j=0, 3 do&lt;br /&gt;
--				for k=1, instructions[i*5 + j + 1] do&lt;br /&gt;
--					to_click[#to_click+1] = button_names[j+1];&lt;br /&gt;
--				end&lt;br /&gt;
--			end&lt;br /&gt;
--			if not (instructions[i*5 + 5] == last_sun) then&lt;br /&gt;
--				last_sun = instructions[i*5 + 5];&lt;br /&gt;
--				to_click[#to_click+1] = button_names[5];&lt;br /&gt;
--			end&lt;br /&gt;
--			if #to_click &amp;gt; 0 then&lt;br /&gt;
--				clickAllComplex(to_click, (&amp;quot;(&amp;quot; .. loops .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) &amp;quot; .. i .. &amp;quot;:&amp;quot;));&lt;br /&gt;
--			end&lt;br /&gt;
--			waitForMonChange(&amp;quot;(&amp;quot; .. loops .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Tick &amp;quot; .. i .. &amp;quot; done.&amp;quot;);&lt;br /&gt;
--			if (i == 0) then -- first one immediately finds a change&lt;br /&gt;
--				waitForMonChange(&amp;quot;(&amp;quot; .. loops .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Tick &amp;quot; .. i .. &amp;quot; done.&amp;quot;);&lt;br /&gt;
--			end&lt;br /&gt;
--			if finish_up then&lt;br /&gt;
--				num_loops = loops;&lt;br /&gt;
--			end			&lt;br /&gt;
--		end&lt;br /&gt;
&lt;br /&gt;
		lsSleep(30);&lt;br /&gt;
		clickAllComplex({&amp;quot;Harvest.png&amp;quot;});&lt;br /&gt;
		lsSleep(50);&lt;br /&gt;
		&lt;br /&gt;
		refillWater(); -- Hack - won't work unless things are arranged precisely, and does no checking&lt;br /&gt;
		&lt;br /&gt;
		if finish_up then&lt;br /&gt;
			break;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
abort 32 gardens pinned with window arranger&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
-- To run:&lt;br /&gt;
--  Copy a recipe from the output of the Thistle Mode&lt;br /&gt;
--  Update expected_gardens equal to the number you have opened and pinned&lt;br /&gt;
--    Gardens must all have their buttons visible, can overlap as long as the&lt;br /&gt;
--    row with &amp;quot;asc&amp;quot; is visible regardlesss of which window was clicked last&lt;br /&gt;
--  Update &amp;quot;last sun&amp;quot; to be what it is now (0 if night,&lt;br /&gt;
--    99 if daylight and open lid, 33 if daylight and closed lid)&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
loadfile(&amp;quot;luaScripts/screen_reader_common.inc&amp;quot;)();&lt;br /&gt;
loadfile(&amp;quot;luaScripts/ui_utils.inc&amp;quot;)();&lt;br /&gt;
&lt;br /&gt;
per_click_delay = 0;&lt;br /&gt;
&lt;br /&gt;
local expected_gardens = 32;&lt;br /&gt;
local last_sun = 33;&lt;br /&gt;
&lt;br /&gt;
instructions = {&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,1,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,1,1,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,2,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,2,0,0,&lt;br /&gt;
0,0,0,3,0,&lt;br /&gt;
0,0,1,1,0,&lt;br /&gt;
0,0,1,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,1,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,1,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,2,0,&lt;br /&gt;
0,0,1,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,1,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
0,0,0,0,0,&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local window_locs = {};&lt;br /&gt;
&lt;br /&gt;
function setWaitSpot(x0, y0)&lt;br /&gt;
	setWaitSpot_x = x0;&lt;br /&gt;
	setWaitSpot_y = y0;&lt;br /&gt;
	setWaitSpot_px = srReadPixel(x0, y0);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function waitForChange()&lt;br /&gt;
	local c=0;&lt;br /&gt;
	while srReadPixel(setWaitSpot_x, setWaitSpot_y) == setWaitSpot_px do&lt;br /&gt;
		lsSleep(1);&lt;br /&gt;
		c = c+1;&lt;br /&gt;
		if (lsShiftHeld() and lsControlHeld()) then&lt;br /&gt;
			error 'broke out of loop from Shift+Ctrl';&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- lsPrintln('Waited ' .. c .. 'ms for pixel to change.');&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function clickAll(image_name, up)&lt;br /&gt;
	-- Find buttons and click them!&lt;br /&gt;
	srReadScreen();&lt;br /&gt;
	xyWindowSize = srGetWindowSize();&lt;br /&gt;
	local buttons = findAllImages(image_name);&lt;br /&gt;
	&lt;br /&gt;
	if #buttons == 0 then&lt;br /&gt;
		statusScreen(&amp;quot;Could not find specified buttons...&amp;quot;);&lt;br /&gt;
		lsSleep(150);&lt;br /&gt;
	else&lt;br /&gt;
		statusScreen(&amp;quot;Clicking &amp;quot; .. #buttons .. &amp;quot;button(s)...&amp;quot;);&lt;br /&gt;
		if up then&lt;br /&gt;
			for i=#buttons, 1, -1  do&lt;br /&gt;
				srClickMouseNoMove(buttons[i][0]+5, buttons[i][1]+3);&lt;br /&gt;
				lsSleep(per_click_delay);&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			for i=1, #buttons  do&lt;br /&gt;
				srClickMouseNoMove(buttons[i][0]+5, buttons[i][1]+3);&lt;br /&gt;
				lsSleep(per_click_delay);&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		statusScreen(&amp;quot;Done clicking (&amp;quot; .. #buttons .. &amp;quot; clicks).&amp;quot;);&lt;br /&gt;
		lsSleep(100);&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function clickAllComplex(image_names, message)&lt;br /&gt;
	if not message then&lt;br /&gt;
		message = &amp;quot;&amp;quot;;&lt;br /&gt;
	end&lt;br /&gt;
	-- Find buttons and click them!&lt;br /&gt;
	srReadScreen();&lt;br /&gt;
	local dpos = {};&lt;br /&gt;
	for i=1, #image_names do&lt;br /&gt;
		local pos = srFindImageInRange(image_names[i],&lt;br /&gt;
			window_locs[#window_locs][0], window_locs[#window_locs][1],&lt;br /&gt;
			410, 312);&lt;br /&gt;
		if not pos then&lt;br /&gt;
			error ('Failed to find ' .. image_names[i]);&lt;br /&gt;
		end&lt;br /&gt;
		dpos[i] = {};&lt;br /&gt;
		dpos[i][0] = pos[0] - window_locs[#window_locs][0];&lt;br /&gt;
		dpos[i][1] = pos[1] - window_locs[#window_locs][1];&lt;br /&gt;
	end&lt;br /&gt;
	statusScreen(message .. &amp;quot; Clicking &amp;quot; .. #window_locs .. &amp;quot; button(s)...&amp;quot;);&lt;br /&gt;
	local first = 1;&lt;br /&gt;
	for i=#window_locs, 1, -1 do&lt;br /&gt;
		if not first then&lt;br /&gt;
			-- focus&lt;br /&gt;
			setWaitSpot(window_locs[i+1][0], window_locs[i+1][1]);&lt;br /&gt;
			srClickMouseNoMove(window_locs[i][0], window_locs[i][1]);&lt;br /&gt;
			waitForChange();&lt;br /&gt;
		end&lt;br /&gt;
		-- click all buttons&lt;br /&gt;
		for j=1, #image_names do&lt;br /&gt;
			srClickMouseNoMove(window_locs[i][0] + dpos[j][0] + 5, window_locs[i][1] + dpos[j][1] + 5);&lt;br /&gt;
		end&lt;br /&gt;
		first = nil;&lt;br /&gt;
	end&lt;br /&gt;
	lsSleep(100);&lt;br /&gt;
	statusScreen(message .. &amp;quot; Refocusing...&amp;quot;);&lt;br /&gt;
	-- refocus&lt;br /&gt;
	for i=2, #window_locs do&lt;br /&gt;
		setWaitSpot(window_locs[i][0], window_locs[i][1]);&lt;br /&gt;
		srClickMouseNoMove(window_locs[i][0], window_locs[i][1] + 310);&lt;br /&gt;
		waitForChange();&lt;br /&gt;
	end&lt;br /&gt;
	lsSleep(100);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
button_names = {&amp;quot;ThistleNit.png&amp;quot;, &amp;quot;ThistlePot.png&amp;quot;, &amp;quot;ThistleH2O.png&amp;quot;, &amp;quot;ThistleOxy.png&amp;quot;, &amp;quot;ThistleSun.png&amp;quot;};&lt;br /&gt;
&lt;br /&gt;
local z = 2;&lt;br /&gt;
&lt;br /&gt;
-- Initialize last_mon&lt;br /&gt;
local mon_w = 10;&lt;br /&gt;
local mon_h = 152;&lt;br /&gt;
local last_mon = {};&lt;br /&gt;
for x=1, mon_w do&lt;br /&gt;
	last_mon[x] = {};&lt;br /&gt;
	for y=1, mon_h do&lt;br /&gt;
		last_mon[x][y] = 0;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function waitForMonChange(message)&lt;br /&gt;
	if not first_nit then&lt;br /&gt;
		first_nit = srFindImage(&amp;quot;ThistleNit.png&amp;quot;);&lt;br /&gt;
	end&lt;br /&gt;
	if not first_nit then&lt;br /&gt;
		error &amp;quot;Could not find first Nit&amp;quot;;&lt;br /&gt;
	end&lt;br /&gt;
	mon_x = first_nit[0] - 25;&lt;br /&gt;
	mon_y = first_nit[1] + 13;&lt;br /&gt;
		&lt;br /&gt;
	local different = nil;&lt;br /&gt;
	local skip_next = nil;&lt;br /&gt;
	local first_loop = 1;&lt;br /&gt;
	while not different do&lt;br /&gt;
		srReadScreen();&lt;br /&gt;
		for x=1, mon_w do&lt;br /&gt;
			for y=1, mon_h do&lt;br /&gt;
				newvalue = srReadPixelFromBuffer(mon_x + x, mon_y + y);&lt;br /&gt;
				if not (newvalue == last_mon[x][y]) then&lt;br /&gt;
					different = 1;&lt;br /&gt;
				end&lt;br /&gt;
				last_mon[x][y] = newvalue;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if not different then&lt;br /&gt;
			first_loop = nil;&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		if different then&lt;br /&gt;
			-- Make sure the screen was done refreshing and update again&lt;br /&gt;
			lsSleep(60);&lt;br /&gt;
			srReadScreen();&lt;br /&gt;
			for x=1, mon_w do&lt;br /&gt;
				for y=1, mon_h do&lt;br /&gt;
					last_mon[x][y] = srReadPixelFromBuffer(mon_x + x, mon_y + y);&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		if (different and skip_next) then&lt;br /&gt;
			skip_next = nil;&lt;br /&gt;
			different = nil;&lt;br /&gt;
		end &lt;br /&gt;
		&lt;br /&gt;
		lsPrintWrapped(10, 5, 0, lsScreenX - 20, 1, 1, 0xFFFFFFff, message);&lt;br /&gt;
		lsPrintWrapped(10, 60, 0, lsScreenX - 20, 1, 1, 0xFFFFFFff, &amp;quot;Waiting for change...&amp;quot;);&lt;br /&gt;
		if lsButtonText(lsScreenX - 110, lsScreenY - 30, z, 100, 0xFFFFFFff, &amp;quot;End script&amp;quot;) then&lt;br /&gt;
			error &amp;quot;Clicked End Script button&amp;quot;;&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if lsButtonText(40, lsScreenY - 60, z, 200, 0xFFFFFFff, &amp;quot;Force tick&amp;quot;) then&lt;br /&gt;
			different = 1;&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if lsButtonText(40, lsScreenY - 90, z, 200, 0xFFFFFFff, &amp;quot;Skip tick&amp;quot;) then&lt;br /&gt;
			skip_next = 1;&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		if lsButtonText(40, lsScreenY - 120, z, 200, 0xFFFFFFff, &amp;quot;Finish up&amp;quot;) then&lt;br /&gt;
			finish_up = 1;&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		-- display mon pixels&lt;br /&gt;
		for x=1, mon_w do&lt;br /&gt;
			for y=1, mon_h do&lt;br /&gt;
				local size = 2;&lt;br /&gt;
				lsDisplaySystemSprite(1, 10+x*size, 90+y*size, 0, size, size, last_mon[x][y]);&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		lsDoFrame();&lt;br /&gt;
		lsSleep(100);&lt;br /&gt;
	end&lt;br /&gt;
	statusScreen(&amp;quot;Changed, waiting a moment for other beds to catch up...&amp;quot;);&lt;br /&gt;
	if not first_loop then -- Don't wait, we might be behind already!&lt;br /&gt;
		lsSleep(150); -- Wait a moment after image changes before doing the next tick&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function test()&lt;br /&gt;
&lt;br /&gt;
	local loop=0;&lt;br /&gt;
	while 1 do&lt;br /&gt;
		waitForMonChange(&amp;quot;tick &amp;quot; .. loop);&lt;br /&gt;
		&lt;br /&gt;
		statusScreen('Changed!');&lt;br /&gt;
		lsSleep(100);&lt;br /&gt;
		loop = loop + 1;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	error 'done';&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
 function refillWater()&lt;br /&gt;
--	statusScreen(&amp;quot;Refilling water...&amp;quot;);&lt;br /&gt;
--	srClickMouseNoMove(359, 13);&lt;br /&gt;
--	lsSleep(100);&lt;br /&gt;
--	srClickMouseNoMove(srGetWindowSize()[0]/2 + 10, srGetWindowSize()[1]/2 + 20);&lt;br /&gt;
--	lsSleep(4000);&lt;br /&gt;
	lsSleep(1000);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function doit()&lt;br /&gt;
	num_loops = 1;&lt;br /&gt;
	askForWindow(&amp;quot;Pin any number of thistle gardnes, edit thistle_custom with recipe.&amp;quot;);&lt;br /&gt;
	&lt;br /&gt;
	if not ( #instructions == 41*5) then&lt;br /&gt;
		error 'Invalid instruction length';&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	srReadScreen();	&lt;br /&gt;
	window_locs = findAllImages(&amp;quot;ThisIs.png&amp;quot;);&lt;br /&gt;
	if not (#window_locs == expected_gardens) then&lt;br /&gt;
		error (&amp;quot;Did not find expected number of thistle gardens (found &amp;quot; .. #window_locs .. &amp;quot; expected &amp;quot; .. expected_gardens .. &amp;quot;)&amp;quot;);&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
--	wl2 = {};&lt;br /&gt;
--	wl2[1] = window_locs[31];&lt;br /&gt;
--	wl2[2] = window_locs[32];&lt;br /&gt;
--	window_locs = wl2;&lt;br /&gt;
--	if not (#window_locs == 2) then&lt;br /&gt;
--		error 'fail';&lt;br /&gt;
--	end&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	-- test();&lt;br /&gt;
	&lt;br /&gt;
	for loops=1, num_loops do&lt;br /&gt;
		&lt;br /&gt;
		-- clickAll(&amp;quot;ThisIs.png&amp;quot;, 1);&lt;br /&gt;
		-- lsSleep(100);&lt;br /&gt;
		&lt;br /&gt;
		srReadScreen();&lt;br /&gt;
		&lt;br /&gt;
		-- clickAllComplex({&amp;quot;Harvest.png&amp;quot;}, 1);&lt;br /&gt;
		-- error 'done';&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		-- clickAllComplex({&amp;quot;ThistleAbort.png&amp;quot;}, 1);&lt;br /&gt;
		-- error 'done';&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		-- statusScreen(&amp;quot;(&amp;quot; .. loops .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Doing initial 2s wait...&amp;quot;);&lt;br /&gt;
		-- lsSleep(200);&lt;br /&gt;
		--waitForMonChange(&amp;quot;Getting initial image...&amp;quot;);&lt;br /&gt;
--		for i=0, 39 do&lt;br /&gt;
--			local to_click = {};&lt;br /&gt;
--			if (i == 0) then&lt;br /&gt;
--				to_click[1] = &amp;quot;ThistlePlantACrop.png&amp;quot;;&lt;br /&gt;
--			end&lt;br /&gt;
--			for j=0, 3 do&lt;br /&gt;
--				for k=1, instructions[i*5 + j + 1] do&lt;br /&gt;
--					to_click[#to_click+1] = button_names[j+1];&lt;br /&gt;
--				end&lt;br /&gt;
--			end&lt;br /&gt;
--			if not (instructions[i*5 + 5] == last_sun) then&lt;br /&gt;
--				last_sun = instructions[i*5 + 5];&lt;br /&gt;
--				to_click[#to_click+1] = button_names[5];&lt;br /&gt;
--			end&lt;br /&gt;
--			if #to_click &amp;gt; 0 then&lt;br /&gt;
--				clickAllComplex(to_click, (&amp;quot;(&amp;quot; .. loops .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) &amp;quot; .. i .. &amp;quot;:&amp;quot;));&lt;br /&gt;
--			end&lt;br /&gt;
--			waitForMonChange(&amp;quot;(&amp;quot; .. loops .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Tick &amp;quot; .. i .. &amp;quot; done.&amp;quot;);&lt;br /&gt;
--			if (i == 0) then -- first one immediately finds a change&lt;br /&gt;
--				waitForMonChange(&amp;quot;(&amp;quot; .. loops .. &amp;quot;/&amp;quot; .. num_loops .. &amp;quot;) Tick &amp;quot; .. i .. &amp;quot; done.&amp;quot;);&lt;br /&gt;
--			end&lt;br /&gt;
--			if finish_up then&lt;br /&gt;
--				num_loops = loops;&lt;br /&gt;
--			end			&lt;br /&gt;
--		end&lt;br /&gt;
&lt;br /&gt;
		lsSleep(500);&lt;br /&gt;
		clickAllComplex({&amp;quot;ThistleAbort.png&amp;quot;});&lt;br /&gt;
		lsSleep(500);&lt;br /&gt;
		srReadScreen();&lt;br /&gt;
		clickAll(&amp;quot;Yes.png&amp;quot;, 1);&lt;br /&gt;
		&lt;br /&gt;
		-- clickAll(&amp;quot;ThisIs.png&amp;quot;, 1);&lt;br /&gt;
&lt;br /&gt;
		lsSleep(500);&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
-- 		refillWater(); -- Hack - won't work unless things are arranged precisely, and does no checking&lt;br /&gt;
		&lt;br /&gt;
		if finish_up then&lt;br /&gt;
			break;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pheros</name></author>
	</entry>
</feed>