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

Can this be improved?

Started by stew3254, 17 May 2016 - 11:17 PM
stew3254 #1
Posted 18 May 2016 - 01:17 AM
This is my first 'complex' program I have ever made . I am new to programming and Computer craft so I wanted to get constrictive criticism on how to make my program better. I also would like to hear comments if people want things added or changed.
Spoilerhttp://pastebin.com/wiPKqNFQ
KingofGamesYami #2
Posted 18 May 2016 - 01:59 AM
1. I would localize your variables
2. Avoid rebooting as much as possible (use a while loop instead)
3. Instead of creating separate functions for different colors, make a single function with an argument
The Higher Realm #3
Posted 18 May 2016 - 05:11 AM
I didn't thoroughly go through the program but the "color()" functions could be summed up to:

local function change_color(rColor)
	if term.isColor() then --You also don't need to put "== true" if it's true
		term.setTextColor(colors[rColor]) -- You can do colors[color] and it is the same as colors.color. This allows using a variable as the color possible.
	end
end

change_color("red") --Then you can call it like so

Instead of making a separate function for every color
Edited by