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

worm game probblems

Started by BigSHinyToys, 18 November 2012 - 03:57 AM
BigSHinyToys #1
Posted 18 November 2012 - 04:57 AM



I launched worm from this program. the color last used by my program became the background.

Program I used
Spoiler

--[[
		Light weight mouse FB mini
		by BigSHinyToys
]]--
local bRun = true
local sSlash = [[]]
local path = {}
local tItemList = {}
local width,hight = term.getSize()
local listPos = -1
local lastListPos
local pading = string.rep(" ",width)
local function stringPath()
	return sSlash..table.concat(path,sSlash)
end
local function newList()
	lastListPos = nil
	listPos = -1
	tItemList = {{n = "..", id = "back"}} -- adds a back item at top of list
	sPath = stringPath()
	local folders = {}
	local files = {}
	local disks = {}
  
	local test,list = pcall(fs.list,sPath) -- stopes fs.list crash
	if list == nil then
		list = {}
	end
	if #path == 0 then
		for i,v in pairs(rs.getSides()) do
			if disk.isPresent(v) then
				if disk.hasData(v) then
					table.insert(tItemList,{n = disk.getMountPath(v), id = "disk",s = v})
					disks[disk.getMountPath(v)] = true
				elseif disk.hasAudio(v) then
					table.insert(tItemList,{n = disk.getAudioTitle(v), id = "audio",s = v})
				end
			end
		end
	end
	for i,v in pairs(list) do
		if fs.isDir(sPath..sSlash..v) then
			table.insert(folders,v)
		else
			table.insert(files,v)
		end
	end
	table.sort(folders)
	table.sort(files)
	for i,v in pairs(folders) do
		if disks[v] == nil then
			table.insert(tItemList,{n = v, id = "folder"})
		end
	end
	for i,v in pairs(files) do
		table.insert(tItemList,{n = v, id = "file"})
	end
end
term.clear()
newList()
local tIcons = {
	back = {tCol = "lightGray",bCol = "blue",txt = " < "},
	disk = {tCol = "lightGray",bCol = "blue",txt = "[*]"},
	audio = {tCol = "yellow",bCol = "red",txt = "(o)"},
	folder = {tCol = "lightGray",bCol = "blue",txt = "[=]"},
	file = {tCol = "lime",bCol = "green",txt = "   "}}
while bRun do
	if lastListPos ~= listPos then
		for i = 2,hight do
			term.setCursorPos(1,i)
			local sel = i+listPos
			if tItemList[sel] then
				term.setBackgroundColor(colors[tIcons[tItemList[sel].id].bCol])
				term.setTextColor(colors[tIcons[tItemList[sel].id].tCol])
				term.write(string.sub(tIcons[tItemList[sel].id].txt..tItemList[sel].n..pading,1,width))
			else
				term.write(pading)
			end
		end
		term.setBackgroundColor(colors.lightBlue)
		term.setTextColor(colors.blue)
		term.setCursorPos(1,1)
		term.write(string.sub(stringPath().."  "..tostring(listPos).." "..#tItemList.." "..hight..pading,1,width))
		lastListPos = listPos
	end
	local event = {os.pullEvent()}
	if event[1] == "mouse_scroll" then
		listPos = math.max(math.min(listPos + event[2],(#tItemList+1) - hight),-1)
	elseif event[1] == "mouse_click" then
		if event[2] == 1 then -- left click
			local itemNumber = event[4] + listPos -- to keep it neat
			if tItemList[itemNumber] then
				if tItemList[itemNumber].id == "folder" or tItemList[itemNumber].id == "disk" then
					table.insert(path,tItemList[itemNumber].n)
				elseif tItemList[itemNumber].id == "file" then
					os.run(getfenv(),stringPath()..sSlash..tItemList[itemNumber].n)
				elseif tItemList[itemNumber].id == "back" then
					table.remove(path,#path)
				end
				newList()
			end
		else -- right click
		end
	elseif event[1] == "window_resize" then
		width,hight = term.getSize()
		lastListPos = nil
	end
end
Sammich Lord #2
Posted 18 November 2012 - 07:59 AM
I believe the Worm script thinks that it already has a black background, because it is supposed to be run from shell, and shell always changes to a black background.
BigSHinyToys #3
Posted 18 November 2012 - 08:05 AM
I believe the Worm script thinks that it already has a black background, because it is supposed to be run from shell, and shell always changes to a black background.
yes that is why and it should be as simple as adding a term.setBackgroundColor() at the start of the script. I know how to work around this by clearing the terminal before running this but it is still a bug so i reported it
Tiin57 #4
Posted 20 November 2012 - 04:21 PM
Not quite a bug; just an oversight that is quite simple to fix if you know anything about the advanced computer API. :/
Mikeemoo #5
Posted 21 November 2012 - 12:21 AM
An oversight is a bug, regardless of how minor or major you feel it is. That's why bugs usually have priorities. See?
dunkee #6
Posted 16 December 2012 - 10:12 PM
Still pretty funky though :P/>