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

Tower of Power

Started by Ralnick, 19 October 2012 - 11:45 PM
Ralnick #1
Posted 20 October 2012 - 01:45 AM
Hello Everyone,

As my first program I offer the Tower of Power.

I know it is very basic and I am sure there are other ways to make it, and to shorten the program, but I am still learning how.

The program is over 240 lines long.. so I will not put it on here.. it will be a link to Pastebin where you can view and if your still alive after seeing the horror you can download it.

pastebin

1Ugw4NYp

This is also going to be the first time I am posting to YouTube. So here is the a short Video to show you how it is made.
(Sorry for the extra noise from in game)

Video on YouTube


please all constructive criticism is welcome.
Matrixmage #2
Posted 20 October 2012 - 02:03 AM
You are right that you can shorten the program, and I got a little tip to help with that. If I'm correct the program repeats the same code over, the way you can shorten it is by creating a function of the code that needs to be repeated, and then use a "for" loop for as many times as you need it. Hope this suggestion helps!

EDIT: After watching the video I see its not the same thing repeating, but you can still have separate functions for each step then "for" loops. Once again, hope this helps!
Ralnick #3
Posted 20 October 2012 - 02:11 AM
thanks for that..

i am not sure how to work with Functions yet.. but I am doing more reading on it.. (I am sure this is easy for most but for some reason I am at a loss) old dogs and new tricks… sort of thing…
Matrixmage #4
Posted 20 October 2012 - 02:21 AM
A easy way of thinking of functions are that they are singular re-callable pieces of code.


Example:


function hi()
    print("Functions are awesome!")
end

hi()

This would print "Functions are awesome!", easy enough?

I made a GPS tower building program and made a "move" function for moving the turtle rather then having to write "turtle.forward()" over and over. All of the "turtle" api code are functions. Don't know if this helps but hope it does!

If you need some more help check here:

http://www.computerc...ials-resources/

This has lots of tutorials for some extra help.
ChunLing #5
Posted 20 October 2012 - 03:29 AM
The gox commands are a good place to start learning some basic programming, due to the fact that they support loops.

There are two types of loop in a gox command. A bracketed sequence like "[fo]" will repeat until the last command returns false. So if you loaded some blocks into the selected slot of the turtle, and then used gox with a command string of "[fo]", it will move forward one and then place down a block, until it ran out of blocks or tried to place one where there was already a block (if, on the other hand, you type in "[of]", it just keeps on going till it can go no more…and the 'f' command nearly always returns true).

The other type of loop is a bracketed sequence followed by a number, like "[fo]10". In this case, the sequence only repeats ten times, regardless of whether it could continue or even if the placeDown repeatedly fails.

These two loops roughly correspond to "repeat … until ." and "for i = 1,n do … end" loops.

The "ldstrng" command is a good way to test out a simple function…but you should make not to use it if your turtle is inaccessible, cause it has a good chance of dumping you out of clfn with an error if the code you give it is bad.
jwplayer0 #6
Posted 19 December 2012 - 12:52 PM
Does anyone have a backup copy of this program?
ChunLing #7
Posted 19 December 2012 - 01:15 PM
Probably not. It was a fairly simple and specific code (long because it didn't use functions or loops).