The above code is a library that I use for my menus and buttons. It does work. The problem is that I can't seem to get the code to work. ?. Look at my code below. and it should make some sense to you. The idea is to start and stop trains (railcarft) using signals from bundled cable. with menus and buttons. The idea is to update the menu as well as sending signals out and being able to to turn the signals off. I just don't think I under stand the rules for coding in lua. For a sample. Look at isRefueling. When this is turned on, It sends a signal to a switch motor then switches a train track. Sending the train to refuel. When you stop trains and they have been sitting for a while. and not knowing how much fuel is left. I thought this was a good idea.
Can some one help me code this.
local scr = require("screen")
local component = require("component")
local colors = require("colors")
local rs = component.redstone
local event = require("event")
local term = require("term")
local sides = require("sides")
local rs = component.redstone
isRefueling = false
isCityActive = false
isTownActive = false
local win = scr:newPane(win, 50, 25)
term.clear()
win:center()
win:box(1, 1, 50, 25, 0x999999)
win:centerText(1, 10, 50, 0x999999, 0x000000, "Trains Main Menu.")
win:button("Start / Stop Town "..tostring(IsTownActive), 19, 12, 25, 3, 0xFF0000, "town")
win:button("Start / Stop City "..tostring(isCityActive), 19, 14, 25, 3, 0xFF0000, "city")
if isRefueling == false then
win:button("Refuel On "..tostring(isRefueling), 19, 16, 20, 3, 0xFF0000, "refueloff")
elseif isRefueling then
win:button("Refuel Off "..tostring(isRefueling), 19, 16, 20, 3, 0xFF0000, "refuelon")
end
win:button("Exit me",19 , 22, 20, 3, 0xFF0000, "exit")
win:render()
function startIt(mode, place)
if place == "city" then
if mode == "on" then
rs.setBundledOutput(sides.north, colors.lime, 255) --Starts train for city
rs.setBundledOutput(sides.north, colors.pink, 0) -- Turns Parks off
isCityActive = true
elseif mode == "off" then
rs.setBundledOutput(sides.north, colors.pink, 255) -- Stops Train
rs.setBundledOutput(sides.north, colors.lime, 0) -- Turn Start off
isCityActive = false
end
elseif place == "town" then
if mode == "on" then
rs.setBundledOutput(sides.north, colors.green, 255) -- Starts train for town
rs.setBundledOutput(sides.north, colors.red, 0) -- turns Stop off
isTownActive = true
elseif mode == "off" then
rs.setBundledOutput(sides.north, colors.green, 0) -- Shuts train city off
rs.setBundledOutput(sides.north, colors.red, 255) -- Stops Train
isTownActive = true
end
end
end
function Refueling(mode)
if mode == "on" then
rs.setBundledOutput(sides.north, colors.blue, 255)
isReFueling = true
elseif mode == "off" then
rs.setBundledOutput(sides.north, colors.blue, 0)
isRefueling = false
end
end
local function run(ev, p1, p2, p3, p4, p5)
if ev == "touch" then
if win:clicked(p2, p3) then
ret = win:buttonClicked(p2, p3)
if ret == "town" then
term.clear()
win:render()
elseif ret == "city" then
if isCityActive == true then
startIt("on","city")
elseif isCityActive == false then
startIt("off","city")
end
elseif ret == "refuelon" then
Refueling("on")
elseif ret == "refueloff" then
Refueling("off")
elseif ret == "exit" then
term.clear()
running = false
end
end
elseif ev == "key_down" then
term.clear()
running = false
end
end
running = true
repeat
local ev, p1, p2, p3, p4, p5 = event.pull(.5, _, ev, p1, p2, p3, p4, p5)
run(ev, p1, p2, p3, p4, p5)
until running == false
term.clear()
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.
I don't think I under stand the lua rules. I have done programming in C# and lua is nothing like c#.
http://pastebin.com/6D6wpqSB Save in your library folder as "screen.lua"
The above code is a library that I use for my menus and buttons. It does work. The problem is that I can't seem to get the code to work. ?. Look at my code below. and it should make some sense to you. The idea is to start and stop trains (railcarft) using signals from bundled cable. with menus and buttons. The idea is to update the menu as well as sending signals out and being able to to turn the signals off. I just don't think I under stand the rules for coding in lua. For a sample. Look at isRefueling. When this is turned on, It sends a signal to a switch motor then switches a train track. Sending the train to refuel. When you stop trains and they have been sitting for a while. and not knowing how much fuel is left. I thought this was a good idea.
Can some one help me code this.
Link to post
Share on other sites