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

Api Info Retrival Issue

Started by Termanater13, 28 July 2013 - 11:42 AM
Termanater13 #1
Posted 28 July 2013 - 01:42 PM
I have created a button api that has a way to retrive any info the play may need, but when I try to manipulate the data it gives me it juat comes up blank. or not completing. I cant figute out where it is having the issue.

pasebin of the full api that I am having issue with Pastebin DWVp5SHU

the function within that API that does the data retrival
Spoiler
-- this function will allow for the user to call info on the button
function info(action, data1, data2)
local returndata = {}
-- allows for the retriving of data based on the button name
if action == "name" then
  if data1 == nil or data1 == "all" then
   -- all data
   for key1, value1 in pairs(ButtonApiData) do
	returndata[key] = {}
	for key2, value2 in pairs(value1) do
	 if key2 ~= "usefunc" then
	  returndata[key1][key2] = value
	 end
	end
   end
   return returndata
  elseif ButtonApiData[data1] then
   -- retrives data on a spicific button
   if data2 == nil or data2 == "all" then
	-- all data of a button
	for key, value in pairs(ButtonApiData[data1]) do
	 if key ~= "usefunc" then
	  returndata[key] = value
	 end
	end
	return returndata
   elseif ButtonApiData[data1][data2] then
	-- returns a spacific button value
	return ButtonApiData[data1][data2]
   end
  else
   return false
  end
-- allows the ability to retrive data based on if it is active or not
elseif action == "status" then
  if data1 == nil or data1 == "all" then
   -- retreives button status
   for key1, value1 in pairs(buttonApiData) do
	for key2, value2 in pairs(value1) do
	 if key2 == "active" then
	  returndata[key1] = value2
	 end
	end
   end
  elseif ButtonApiData[data1] then
   -- returns the data fo the button if it is active or not
   return ButtonApiData[data1]["active"]
  elseif data == status then
   if data2 == "active" or data2 == "on" or data2 == "enabled" or data2 == true then
	-- returns all active buttons
	for key, value in pairs(ButtonApiData) do
	 if ButtonApiData[key]["active"] then
	  returndata[key] = ButtonApiData[key]["active"]
	 end
	end
	return returndata
   elseif data2 == "deactive" or data2 == "off" or data2 == "disabled" or data2 == false then
	-- returns all enactive buttons
	for key, value in pairs(ButtonApiData) do
	 if (not ButtonApiData[key]["active"]) then
	  returndata[key] = ButtonApiData[key]["active"]
	 end
	end
	return returndata
   end
  else
   return false
  end
-- allows for the retrival of current settings
elseif action == "setting" then
  if data1 == nil or data1 == "all" then
   -- returns current setting of all settings
   for key, value in pairs(ButtonApiSetting) do
	returndata[key] = value
   end
   return returndata
  elseif ButtonApiSetting[data1] then
   -- returns the current setting's setting
   return ButtonApiSetting[data1]
  else
   return false
  end
else
  return false
end
end

this is what I am running to produse the data that test2 is evaluating. I named it test(I now the name may not help other then which one Im talking about)
Spoiler
--set all options function
function setup()
	button.setup("wrap","top")
	button.setup("textScale",1)
	button.setup("textColor","pink")

	button.setup("defultOn","magenta")
	button.setup("defultOff","lightBlue")
end
--Page functions
function buttonPage1()
	button.setup("backgroundColor","green")
	button.clearButtons()
	button.new("page2",buttonPage2,1,10,1,3)
	button.new("toggle",toggle,11,20,1,3)
	print("page1")
	button.display()
end
function buttonPage2()
	button.setup("backgroundColor","lime")
	button.clearButtons()
	button.new("page1",buttonPage1,1,10,4,6)
	button.new("toggle",toggle,11,20,1,3)
	print("page2")
	button.display()
end
function toggle()
	button.toggle("toggle")
end
--Begin user functions
setup()
buttonPage1()
while true do
	event,side,x,y = os.pullEvent("monitor_touch")
	button.check(x,y)
	print("loop")
end

the code I am using to evaluate the data being returned so I know it works I named it test2(I now the name may not help other then which one Im talking about)
Spoiler
a = {}
a = button.info("name")
for key1, value1 in pairs(a) do
	print(key1," ",value1)
	for key2, value2 in pairs(value1) do
		print(key2," ",value2)
		print(value2["xmin"].." "..value2["xmax"])
	end
end

I am running test, then terminating it to run test2. I can pull data from the api in the lua test area but in test 2 the second for loop does nothing. the first one prints data but the second does not. im tring to figure it out to see if it is my API, or my test2 code thats the issue and I can see where the problem could be. it is not giving me any errors.
Yevano #2
Posted 28 July 2013 - 06:32 PM
What is this even supposed to be used for? Filtering buttons by their fields?
Termanater13 #3
Posted 28 July 2013 - 07:48 PM
What is this even supposed to be used for? Filtering buttons by their fields?
that was kinda the piont, so the user can base what a button does based on other buttons like an "are you sure button"