Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
SilentCid

Updating items on screen

Question

Greetings,

I'm new to Lua but familiar with some of the basics. I'm using this library for the GUI, but not sure on the proper procedure on updating the items on the screen. I have an adapter attached to an IC2 fluid reactor and want to call reactor.getHeat() to get the latest temps and update this child:

application:addChild(GUI.text(5, 5, 0xFFFFFF, currentTemps))

If someone can kindly point me in the right direction I think I can go from there. The rest of my code is pretty basic which I haven't played around much on it.

local GUI = require("GUI")
local component = require 'component'
local reactor = component.reactor_chamber
local currentTemps = reactor.getHeat()
--------------------------------------------------------------------------------

-- Create new application
local application = GUI.application()

-- Add panel that fits application
application:addChild(GUI.panel(1, 1, application.width, application.height, 0x262626))
-- Add smaller panels
application:addChild(GUI.panel(4, 2, 23, 4, 0x880000))
application:addChild(GUI.text(5, 3, 0xFFFFFF, "Current Reactor Temps"))
application:addChild(GUI.text(5, 5, 0xFFFFFF, currentTemps))

--------------------------------------------------------------------------------

application:draw(true)
application:start()

 

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

I'm not super familiar with this library so you may have to adjust the code as it is untested.

local GUI = require("GUI")
local component = require 'component'
local thread = require 'thread'
local event = require 'event'

local reactor = component.reactor_chamber
local currentTemps = reactor.getHeat()
--------------------------------------------------------------------------------

-- Create new application
local application = GUI.application()

-- Add panel that fits application
application:addChild(GUI.panel(1, 1, application.width, application.height, 0x262626))
-- Add smaller panels
application:addChild(GUI.panel(4, 2, 23, 4, 0x880000))
application:addChild(GUI.text(5, 3, 0xFFFFFF, "Current Reactor Temps"))

-- Grab a reference to the text object you need to update
local gui_temp = GUI.text(5, 5, 0xFFFFFF, currentTemps)
application:addChild(gui_temp)

-- Create a timer that will run every 3 seconds, forever.
local tid = event.timer(3, function()
    gui_temp.text = tostring(reactor.getHeat()) -- overwrite the text data
    gui_temp:update() -- notify the app that the state of gui_temp has changed
  end, math.huge)

--------------------------------------------------------------------------------

application:draw(true)
application:start()
event.cancel(tid) -- cleanup the timer after application:start returns

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.