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

Cant Find Whats Wrong With Code D:

Started by ian43004, 12 August 2015 - 08:13 PM
ian43004 #1
Posted 12 August 2015 - 10:13 PM
Im making a sign for a random thing im working on, its supposed to change colors, from my side of things but it wont work!


while true do
m = peripheral.wrap("TOP")
m.setTextScale(3)
m.setCursorPos(1,1)
m.setTextColor(16384)
m.write("Neon Craft Ultra!")
m.clear()
m.setTextScale(3)
m.setCursorPos(1,1)
m.setTextColor(1)
m.write("Neon Craft Ultra!")
m.clear()
m.setTextScale(3)
m.setCursorPos(1,1)
m.setTextColor(4)
m.write("Neon Craft Ultra!")
m.clear()
m.setTextScale(3)
m.setCursorPos(1,1)
m.setTextColor(32)
m.write("Neon Craft Ultra!")
m.clear()
m.setCursorPos(1,1)
m.setTextColor(512)
m.write("Neon Craft Ultra!")
m.clear()
m.setTextScale(3)
m.setCursorPos(1,1)
m.setTextColor(2048)
m.write("Neon Craft Ultra!")
m.clear()
end
Cranium #2
Posted 13 August 2015 - 12:05 AM
You should be wrapping "top" rather than "TOP". Capitalization and spelling is important in Lua.
Bomb Bloke #3
Posted 13 August 2015 - 01:44 AM
By combining a table and a for loop, we can shrink things down quite a bit:

local cols = {16384, 1, 4, 32, 512, 2048}
local m = peripheral.wrap("top")
m.setTextScale(3)
m.clear()

while true do
	for i = 1, #cols do
		m.setCursorPos(1,1)
		m.setTextColor(cols[i])
		m.write("Neon Craft Ultra!")
		sleep(0.5)
	end
end

Or, by using math.random() to help us generate the powers of two that represent ComputerCraft colours, we can do:

local m = peripheral.wrap("top")
m.setTextScale(3)
m.clear()

while true do
	m.setCursorPos(1,1)
	m.setTextColor(math.pow(2, math.random(16) - 1))
	m.write("Neon Craft Ultra!")
	sleep(0.5)
end
ian43004 #4
Posted 13 August 2015 - 02:47 PM
Ok, is there a way to add additional code, so i have the rainbow header and solid color for the body of text.

I tried:

local m = peripheral.wrap("top")
m.setTextScale(3)
m.clear()
while true do
	    m.setCursorPos(1,1)
	    m.setTextColor(math.pow(2, math.random(16) - 1))
	    m.write("Neon Craft Ultra!")
	    sleep(0.5)
end
m.setCursorPos(1,2)
m.setTextScale(2)
m.setTextColor(32)
m.write("more and more stuff")

But it didnt work, it came out with no errors but still only did the header
Is it possible i need to redefine the monitor? or put the code before end

thanks for your help, you made it really compact!
flaghacker #5
Posted 13 August 2015 - 05:59 PM
Yup, you need to put that stuff inside or preferably before the while loop. That loop will never terminate, so any code past it won't ever be run.