34 posts
Posted 07 February 2014 - 06:41 PM
Look what i want is an sort of rainbow effect with my text.
my text that i want to show up is Computercraft Shop!!
i want it ti display in different colors.
my code looks like this i get alot of errors everytime and i dont know how to fix.
heres my code
local mon = peripheral.wrap("back")
mon.setTextScale(4)
while true do
mon.clear()
mon.setCursorPos(1,1)
mon.setTextColor(2)
mon.write("Computercraft Shop!!")
sleep(1)
mon.clear()
mon.setCursorPos(1,1)
mon.setTextColor(3)
mon.write("Computercraft Shop!!")
sleep(1)
mon.clear()
mon.setCursorPos(1,1)
mon.setTextColor(4)
mon.write("Computercraft Shop!!")
sleep(1)
mon.clear()
mon.setCursorPos(1,1)
mon.setTextColor(5)
mon.write("Computercraft Shop!!")
sleep(1)
mon.clear()
mon.setCursorPos(1,1)
mon.setTextColor(6)
mon.write("Computercraft Shop!!")
sleep(1)
end
995 posts
Location
Canada
Posted 07 February 2014 - 06:47 PM
Please indent. You use colors with the colors API (search it up on the wiki) like this:
local mon = peripheral.wrap("back")
mon.setTextScale(4)
mon.clear()
while true do
mon.setCursorPos(1,1)
mon.setTextColor(colors.red)
mon.write("Computercraft Shop!!")
sleep(1)
mon.setCursorPos(1,1)
mon.setTextColor(colors.orange)
mon.write("Computercraft Shop!!")
sleep(1)
mon.setCursorPos(1,1)
mon.setTextColor(colors.yellow)
mon.write("Computercraft Shop!!")
sleep(1)
mon.setCursorPos(1,1)
mon.setTextColor(colors.lime)
mon.write("Computercraft Shop!!")
sleep(1)
mon.setTextColor(colors.blue)
mon.write("Computercraft Shop!!")
sleep(1)
mon.setCursorPos(1, 1)
mon.setTextColor(colors.purple)
mon.write("Computercraft Shop!!")
sleep(1)
end
Also, please describe the error in more detail.
Edited on 07 February 2014 - 05:48 PM
1281 posts
Posted 07 February 2014 - 06:51 PM
3,5 and 6 aren't even colors… clearing the monitor when you are overwriting the text that's already on it is unnesacary, and there is a much easier way to do this.
local mon = peripheral.wrap("back")
mon.setTextScale(4)
while true do
for k,v in pairs(colors) do -- iterate through the color table
if type(v) == "number" then -- since it contains more than just the color numbers, we have to make sure the value we're using is a number
mon.setCursorPos(1,1)
mon.setTextColor(v) -- set text color
mon.write("Computercraft Shop!!") --this will overwrite the previously written text, if any
sleep(1)
end
end
end
7083 posts
Location
Tasmania (AU)
Posted 07 February 2014 - 06:55 PM
Refer to
the colours API to see the different shades available - you'll notice that there's none with a value of 3, 5, or 6: They're all powers of two.
A "for" loop would also come in handy here.
local mon = peripheral.wrap("back")
mon.setTextScale(4)
mon.clear()
while true do
for i=1,5 do
mon.setCursorPos(1,1)
mon.setTextColor(math.pow(2,i))
mon.write("Computercraft Shop!!")
sleep(1)
end
end
If i = 1, then math.pow(2,i) raises two to the power of one (returning two).
If i = 2, then math.pow(2,i) raises two to the power of two (returning four).
And so on.
Edited on 07 February 2014 - 05:56 PM
34 posts
Posted 07 February 2014 - 07:00 PM
Refer to
the colours API to see the different shades available - you'll notice that there's none with a value of 3, 5, or 6: They're all powers of two.
A "for" loop would also come in handy here.
local mon = peripheral.wrap("back")
mon.setTextScale(4)
mon.clear()
while true do
for i=1,5 do
mon.setCursorPos(1,1)
mon.setTextColor(math.pow(2,i))
mon.write("Computercraft Shop!!")
sleep(1)
end
end
If i = 1, then math.pow(2,i) raises two to the power of one (returning two).
If i = 2, then math.pow(2,i) raises two to the power of two (returning four).
And so on.
i get this error while using your code: startup:2: attempt to index ? (a nil value)
1281 posts
Posted 07 February 2014 - 07:08 PM
Put a monitor behind your computer…
995 posts
Location
Canada
Posted 07 February 2014 - 07:10 PM
The monitor could be facing behind the computer like this:
c = computer
m = monitor
<---- = direction of the front (black) side
<---- c m ---->
286 posts
Location
United States
Posted 09 February 2014 - 12:23 AM
If you work through
The Complete Monitor Buttons and Control Tutorial Part I you will become a pro at displaying text on monitors, and you will learn a few things about Lua, ComputerCraft and programming. It is why we wrote it – so you could become awesome.
995 posts
Location
Canada
Posted 10 February 2014 - 11:39 AM
Yes, the monitor tutorial surfer linked is quite good. (I admit, I helped with fixing typos and grammar and stuff.) Using touch screens might be a little outside the scope of this issue, but you don't have to read that bit.