Stormworks: Build and Rescue

Stormworks: Build and Rescue

Stormworks Custom Content Workshop
Find, rate and try out the best community vehicles in Stormworks!
EDIT: SOLVED! (Can anyone figure out why my build is not working?)
Hello. I am trying to make a display for my fuel tank. I have tabs for displaying different information. When I try to call a tab draw function normally (
drawTab1()
)
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=3434700613
But when I call it from an array of functions (
drawTab[tab]()
where drawTab is an array of functions and drawTab1() is the first element in that array), it shows me this error:
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=3434701820

It works just fine in the PonyIDE emulator.
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=3434704978
Last edited by Kalevipoeg; 28 Feb @ 6:03am
< >
Showing 1-3 of 3 comments
To specify, the line mentioned in the second screenshot (line 123) is
drawTab[tab]()

And in case you don't want to load up the build, this is what the code looks like (removed some unnecessary parts):
tick = 0 -- Tick count since start of computer liquidFillLevel = 0 gasFillLevel = 0 w = 96 h = 96 -- Bool inputs: press = false -- Number inputs: touchX = 0 touchY = 0 temperature = 0 -- Current temperature of fluid portFlowIn = 0 -- In-flow rate of liquid from liquid port portFlowOut = 0 -- Out-flow rate of liquid from liquid port airFlowIn = 0 -- In-flow rate of liquid from air port airFlowOut = 0 -- Out-flow rate of liquid from air port gasAmount = 0 -- Amount of gas in tank in liters liquidAmount = 0 -- Amount of liquid in tank tankCapacity = 0 -- Total capacity of fluid tank liquidFlowOut = 0 -- Liquid out-flow rate (free connection) tab = 1 -- Current tab -- Tab 1: -- Two sliders. Left slider with the header (LIQUID) showing liquid amount in liters as part of total tank capacity. Right one is the same, but for gas (GAS). function drawTab1() -- Draw labels screen.setColor(255, 255, 255) screen.drawText(3, 3, "liquid:\n"..tostring(math.floor(liquidFillLevel * 10000 + 0.5) / 100).." %") screen.drawText((w/2)+3, 3, "gas:\n"..tostring(math.floor(gasFillLevel * 10000 + 0.5) / 100).." %") -- Draw left slider screen.setColor(41, 255, 234) screen.drawRect(1, 15, w/2-2, h-16) screen.setColor(0, 0, 255) screen.drawRectF(2, math.ceil(h-((h-16)*liquidFillLevel)), w/2-3, math.floor((h-1-16)*liquidFillLevel)) -- Draw right slider screen.setColor(255, 255, 255) screen.drawRect(w/2+1, 15, w/2-2, h-16) screen.setColor(150, 150, 150) screen.drawRectF(w/2+2, math.ceil(h-((h-16)*gasFillLevel)), w/2-3, math.floor((h-1-16)*gasFillLevel)) end -- function drawTab2() end -- Table of tabs drawTab = {drawTab1, drawTab2} -- Tick function that will be executed every logic tick function onTick() press = input.getBool(1) touchX = input.getNumber(3) touchY = input.getNumber(4) temperature = input.getNumber(5) portFlowIn = input.getNumber(6) portFlowOut = input.getNumber(7) airFlowIn = input.getNumber(8) airFlowOut = input.getNumber(9) gasAmount = input.getNumber(10) liquidAmount = input.getNumber(11) tankCapacity = input.getNumber(12) liquidFlowOut = input.getNumber(13) tab = input.getNumber(14) output.setNumber(1,tab) tick = tick + 1 if liquidAmount>0 then liquidFillLevel = liquidAmount/tankCapacity else liquidFillLevel = 0 end if gasAmount>0 then gasFillLevel = gasAmount/tankCapacity else gasFillLevel = 0 end end -- Draw function that will be executed when this script renders to a screen function onDraw() drawTab[tab]() end
Last edited by Kalevipoeg; 27 Feb @ 9:19am
Oakrotic 43 28 Feb @ 12:34am 
Adding a if statement to check if input.getNumber(14) is over 0 before overwriting the tab value seems to solve it.
-- Check if the tab variable is over 0 before overwriting it. if input.getNumber(14) > 0 then tab = input.getNumber(14) end
Last edited by Oakrotic; 28 Feb @ 12:40am
Originally posted by Oakrotic:
Adding a if statement to check if input.getNumber(14) is over 0 before overwriting the tab value seems to solve it.
-- Check if the tab variable is over 0 before overwriting it. if input.getNumber(14) > 0 then tab = input.getNumber(14) end
Thank you. :)
Seems like an obvious solution now, but I'm new to this.
< >
Showing 1-3 of 3 comments
Per page: 1530 50