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

setGlow Giving Illegal Argument Exceptions (Open Peripherals)

Started by ƒyeRee, 19 December 2013 - 08:28 PM
ƒyeRee #1
Posted 19 December 2013 - 09:28 PM
Currently I'm working on a program to change the colors of a Glowstone Illuminator to (almost) every color with a nice transition but my program keeps throwing out "glow:30:java.lang.IllegalArgumentExceptions.
When c.setColor is changed to print it outputs a perfect 0x1210ed and continues on perfectly.


r = 16
g = 16
b = 239
c = peripheral.wrap("top")

function num2hex(num)  --Code I found online to convert dec to hex
    local hexstr = '0123456789abcdef'
    local s = ''
    while num > 0 do
        local mod = math.fmod(num, 16)
        s = string.sub(hexstr, mod+1, mod+1) .. s
        num = math.floor(num / 16)
    end
    if s == '' then s = '0'  
elseif s == 0 then s = '00' 
end
    return s

end
repeat
r = r + 1
b = b - 1
rh = num2hex(r)
gh = num2hex(g)
bh = num2hex(B)/>
print("red = "..rh)
print("green = "..gh)
print("blue = "..bh)
conv = string.format("%s%s%s%s", "0x",rh,gh,bh) -- converts all the hex into a single string
c.setColor(conv)
sleep(1)
until r == 239 and b == 16
ƒyeRee #2
Posted 20 December 2013 - 07:28 PM
fixed it. made it overly complicated. My code probably still is

r = 16
g = 16
b = 239
c = peripheral.wrap("top")

repeat
	    r = r + 1
	    b = b - 1

form = string.format("%x%x%x", r,g,B)/>
sub = string.gsub(form, ", ", "")
dec = tonumber(sub, 16)
c.setColor(dec)
	    sleep(.1)
	    until r == 239 and b == 16

			    repeat
					    g = g + 1
					    r = r - 1
					    form = string.format("%x%x%x", r,g,B)/>
					    sub = string.gsub(form, ", ", "")
					    dec = tonumber(sub, 16)
					    c.setColor(dec)
					    sleep(.1)
					    until g == 239 and r == 16

							    repeat
									    b = b + 1
									    g = g - 1
									    form = string.format("%x%x%x", r,g,B)/>
									    sub = string.gsub(form, ", ", "")
									    dec = tonumber(sub, 16)
									    c.setColor(dec)
									    sleep(.1)
									    until b == 239 and g ==16