This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
nikojoi's profile picture

My First Airship [WIP]

Started by nikojoi, 10 October 2012 - 09:49 PM
nikojoi #1
Posted 10 October 2012 - 11:49 PM
Hey all, I've decided I want to build an Airship to fly me where ever I would like (maybe add a mining arm or weapons later). I have watched a couple youtubers build them and am kind of emulating Direwolf20's design from his season 4 LP.

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()
NIN3 #2
Posted 10 October 2012 - 11:57 PM
Neat, cant wait to see it when its all built.
jag #3
Posted 10 October 2012 - 11:58 PM
Cool!
kei_k #4
Posted 10 October 2012 - 11:59 PM
Im quite exited to see what you're gong to build and the coding is quite messy, maybe i could help you shortening that up a bit and after, can you post up a video clip, that would me much appreciated
ScruffyRules #5
Posted 11 October 2012 - 10:48 AM
Neat, cant wait to see it when its all built.
HEY NIN3 :P/>/>
etopsirhc #6
Posted 11 October 2012 - 10:59 AM
hope it works better for you than me , i tested moving a frame with an attached computer and it crashed my mc client
idk if its all fixed but i hope so ( was using tekkit b4 when it happened )
nikojoi #7
Posted 30 October 2012 - 10:02 PM
Finally got it working in all 6 directions ! It took me forever to get the frames to play nice, I'm still not too sure what I was doing wrong either. But that seems to be the general opinion with frames from what I'm hearing from people.

I'd like to add somethign to it, just a flying platform that can move in 6 different directions all controlled by 1 computer is boring. Too bland. Anyone have any ideas on what I could add ? Whatever it will be I will try to also automate that with CC.
Heracles421 #8
Posted 31 October 2012 - 01:36 AM
Use spoilers to hide your code
Spoiler

Like this
it makes the thread look neater
:P/>/>
DMACNZ #9
Posted 31 October 2012 - 05:17 AM
which lets play video was it
nikojoi #10
Posted 31 October 2012 - 01:02 PM
I just hide the code in spoilers, and linked both Direwolf20's, and FunshineX's videos that I got my ideas from.
KaoS #11
Posted 03 November 2012 - 07:24 AM
attach a long distance forcefield generator with the zapper and block breaker upgrades as a cannon of sorts or you can use dispensers and musket rounds, dynamite, cannon balls or blunderbuss shots. a TNT bombing bay and a spherical force field that can also be activated. balkon's cannons for a defensive firing team to operate along with ccSensors to detect all nearby activity and auto bomb/shoot/lava-drop/forcefield-capture/alarm etc etc. deploying water to swim up to the ship with and GPS radar with continuous ping. that's just off the head