I want to use Computercraft to control it, but I'm still fairly new to programming and lua. I have an pictures of the ship so far (very early construction), and the code to move it down below. A lot of my code has been lifted from others and then mashed together or modified to suit my needs. I got the menu code from a FunshineX video, and it was super helpful.
Any help, suggestions, or just some moral support would be greatly appreciated !
The basalt stone brick are panels, and the marble stone brick are covers. I just find it easier to keep track of which is which this way.
EDIT : Updated my code to add the up and down functions, also made it clear the terminal when you choose a direction.
EDIT 2: Finally added the engines for the other 5 directions, also added purple lamps for light at night.
EDIT 3: Linked the videos that I got the design of the airship, and the menu coding from. Also hid the code to make the topic prettier. :P/>/>
Spoiler
--[[Local Variables]]--
local inMenu = true
local selectedItem = 1
--[[Moving methods]]--
function pulse(side, color, time)
rs.setBundledOutput(side, color, true)
sleep(time/2)
rs.setBundledOutput(side, 0)
sleep(time/2)
end
function forward(t)
term.clear()
term.setCursorPos(1,1)
write("How far forward ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.white, 0.8)
end
end
function back(t)
term.clear()
term.setCursorPos(1,1)
write("How far back ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.orange, 0.8)
end
end
function left(t)
term.clear()
term.setCursorPos(1,1)
write("How far left ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.magenta, 0.8)
end
end
function right(t)
term.clear()
term.setCursorPos(1,1)
write("How far right ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.lightBlue, 0.8)
end
end
function up(t)
term.clear()
term.setCursorPos(1,1)
write("How far up ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.yellow, 0.8)
end
end
function down(t)
term.clear()
term.setCursorPos(1,1)
write("How far down ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.lime, 0.8)
end
end
function exit()
inMenu = false
end
--[[Menu Definitions]]--
mainMenu = {
[1] = { text = "Forward", handler = forward },
[2] = { text = "Back", handler = back },
[3] = { text = "Left", handler = left },
[4] = { text = "Right", handler = right },
[5] = { text = "Up", handler = up },
[6] = { text = "Down", handler = down },
[7] = { text = "Exit", handler = exit }
}
--[[Printing Methods]]--
function printMenu( menu )
for i=1,#menu do
if i == selectedItem then
print(">> "..menu[i].text)
else
print(" "..menu[i].text)
end
end
end
--[[Handling Methods]]--
function onKeyPressed( key, menu )
if key == 28 then
onItemSelected(menu)
elseif key == 200 then
if selectedItem > 1 then
selectedItem = selectedItem - 1
end
elseif key == 208 then
if selectedItem < #menu then
selectedItem = selectedItem + 1
end
end
end
function onItemSelected( menu )
menu[selectedItem].handler()
end
--[[Main Method]]--
function main()
while inMenu do
term.clear()
term.setCursorPos(1,1)
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed(key,mainMenu)
end
end
main()