Panakotta00 / FicsIt-Networks

Control, Monitor, Manage and Automate your Satisfactory.
https://ficsit.app/mod/FicsItNetworks
GNU General Public License v3.0
156 stars 51 forks source link

component.findComponent(findClass("Screen")) bug #185

Closed kfpopeye closed 2 years ago

kfpopeye commented 2 years ago

I have no idea why but the code below works. I purposely sabotaged the part about getting the screen but it still displays info to the screen.

The story I originally copied parts of your "Random Plot" example and used this to get the screen: component.findComponent(findClass("Screen"))[1] which worked fine but when I tried the exact same setup at 4 other train stations nothing would display on the screen. When I switched to addressing the screen directly (IE/ component.proxy("B58895234477BC6EC6C3FCAC68B3A392")) then all the screens worked properly. So I thought maybe findClass() was returning ALL screens in the game but it doesn't after all.

function printScreen(str)
 -- displays next stop information about train
 print(str)
 clearScreen()
 local line0 = string.format("%-20s", station.name)
 local line1 = " Next stop:"
 local line2 = " " .. str
 local i = 0
 while (i < 20) do
  gpu:setBackground(0, 0.5, 1.0, 0.5)
  gpu:setForeground(0, 0, 0, 1)
  gpu:setText(0, 0, string.sub(line0, 1, (i + 1)))
  gpu:setBackground(0, 0, 0, 0)
  gpu:setForeground(1, 1, 1, 1)
  gpu:setText(0, 1, string.sub(line1, 1, (i + 1)))
  gpu:setText(0, 2, string.sub(line2, 1, (i + 1)))
  gpu:flush()
  i = i + 1
  event.pull(0.0625)
 end
end

function clearScreen()
 gpu:setBackground(0, 0, 0, 0)
 gpu:setForeground(1, 1, 1, 1)
 gpu:fill(0, 0, w, h, " ")
end

-- get first T1 GPU avialable from PCI-Interface
gpu = computer.getPCIDevices(findClass("GPUT1"))[1]
if not gpu then
 error("No GPU T1 found!")
end

screen = nil
if not screen then
 local comp = component.findComponent(findClass("Screen"))[1]
 if not comp then
  error("No Screen found!")
 end
 --screen = component.proxy(comp)function printScreen(str)
 print(str)
 clearScreen()
 local line0 = string.format("%-20s", station.name)
 local line1 = " Next stop:"
 local line2 = " " .. str
 local i = 0
 while (i < 20) do
  gpu:setBackground(0, 0.5, 1.0, 0.5)
  gpu:setForeground(0, 0, 0, 1)
  gpu:setText(0, 0, string.sub(line0, 1, (i + 1)))
  gpu:setBackground(0, 0, 0, 0)
  gpu:setForeground(1, 1, 1, 1)
  gpu:setText(0, 1, string.sub(line1, 1, (i + 1)))
  gpu:setText(0, 2, string.sub(line2, 1, (i + 1)))
  gpu:flush()
  i = i + 1
  event.pull(0.0625)
 end
end

function clearScreen()
 gpu:setBackground(0, 0, 0, 0)
 gpu:setForeground(1, 1, 1, 1)
 gpu:fill(0, 0, w, h, " ")
end

-- get first T1 GPU avialable from PCI-Interface
gpu = computer.getPCIDevices(findClass("GPUT1"))[1]
if not gpu then
 error("No GPU T1 found!")
end

-- get first Screen-Driver available from PCI-Interface
--local screen = component.proxy("B58895234477BC6EC6C3FCAC68B3A392")
--if not screen then
-- error("No screen")
--end

-- get first Screen
screen = nil
if not screen then
 local comp = component.findComponent(findClass("Screen"))[1]
 if not comp then
  error("No Screen found!")
 end
end

station = component.proxy("A29A211244D1514CEB6C128E2335F462")
if not station then error("No station found!") end

-- setup gpu
gpu:bindScreen(nil)
gpu:setSize(20, 3)
w,h = gpu:getSize()
print("Res:", w, h)
clearScreen()

while true do
 t_table = station:getTrackGraph():getTrains()[1]:getTimeTable()
 if(t_table:getCurrentStop()) then
  nextStop = t_table:getStops()[t_table:getCurrentStop() + 1].station.name
 else
  nextSop = "Unknown"
 end
 printScreen(nextStop)
 event.pull(2)
end
end

station = component.proxy("A29A211244D1514CEB6C128E2335F462")
if not station then error("No station found!") end

-- setup gpu
gpu:bindScreen(nil)
gpu:setSize(20, 3)
w,h = gpu:getSize()
print("Res:", w, h)
clearScreen()

while true do
 t_table = station:getTrackGraph():getTrains()[1]:getTimeTable()
 if(t_table:getCurrentStop()) then
  nextStop = t_table:getStops()[t_table:getCurrentStop() + 1].station.name
 else
  nextSop = "Unknown"
 end
 printScreen(nextStop)
 event.pull(2)
end
Panakotta00 commented 2 years ago

Maybe a stupid question, but when you used the code from the docs as is... have you maybe had a screen driver install on your computer? Like, cuz the samples of the docs first try to get a reference to a screen driver and only then do they try to get a screen in the component network, so maybe just didnt notice that it was actuallly drawing to the screen driver

kfpopeye commented 2 years ago

Yes I have a screen driver on each computer. I was just wondering if because the code above works there might be something wrong going on. The code shouldn't work because I never find a reference to the screen.

Panakotta00 commented 2 years ago

the above code makes sense... it would be better if you share the code that does not work... because if you use the same code for getting the screen as in the docs... you may have used the screen driver instead of the large screen (the screen driver is used to add a "screen" tab to the UI of the computer), because the code in the docs will use the screen driver if available and if that is not available then it uses the large screen

kfpopeye commented 2 years ago

Does gpu:bindScreen(nil) just grab the first screen it can find then?

Panakotta00 commented 2 years ago

PLz refrain from using this a means of Q&A ^^ Thats something for our discord server ^^

And nope, that would simply unbind the screen from the gpu if the gpu is bound to any