Page 1 of 1

Im New, And I Need Some Help.

Posted: Sat Jun 06, 2009 5:41 pm
by Neverfly
Yo, Im new here [ In fact VERY new, I just downloaded LOVE 10 minutes ago ], and.. I need some help.
In the update function, is there a function to overload setBackgroundColor?

Heres the Code that I have:

Code: Select all

Cor = coroutine.create(function()
while true do
local a = math.random(1,255)
local b = math.random(1,255)
local c = math.random(1,255)
coroutine.yield(a,b,c)
end
end)



function load()
Text = love.graphics.newFont(love.default_font,12)
love.graphics.setFont(Text)
Message = "Neverfly"
love.graphics.setBackgroundColor(200,0,0)
x = 50
y = 100
a,b,c = 0,0,0
end


function update(dt)
love.graphics.setBackgroundColor(coroutine.resume(Cor, a, b,c)) -- ERROR HERE!
if love.keyboard.isDown(love.key_right) then
x = x + 5
elseif love.keyboard.isDown(love.key_left) then
x = x - 5
end
if love.keyboard.isDown(love.key_up) then
y = y -5
elseif love.keyboard.isDown(love.key_down) then
y = y + 5
end
end

function draw()
love.graphics.draw("Y Value is: ["..x.."]", 1, 15)
love.graphics.draw("X Value is: ["..y.."]", 1, 30)
   love.graphics.draw(Message, x, y)
   end
Think ya can help?

Re: Im New, And I Need Some Help.

Posted: Sat Jun 06, 2009 7:17 pm
by rude
Welcome to LÖVE, dawg.

I've never used coroutines. That's right; never, so when I ask if the error message by any chance is "attempt to yield across C boundary", it is certainly a shot in the dark.

Re: Im New, And I Need Some Help.

Posted: Sat Jun 06, 2009 7:23 pm
by osgeld
theres no real reason to even use a coroutine here, just stick it in a function and call it when you need a new random color

ive been scripting with lua in various forms since early 2007, and i personally have never found a real use for coroutines

Re: Im New, And I Need Some Help.

Posted: Sat Jun 06, 2009 10:41 pm
by Star Crunch
coroutine.resume() returns a boolean as the first argument, followed by your yield values. So you're doing something like love.graphics.setBackgroundColor(true, 38, 92).

If you don't need fine control, like checking the coroutine status and such, you may want to go with coroutine.wrap() instead.

Re: Im New, And I Need Some Help.

Posted: Sat Jun 06, 2009 11:25 pm
by Neverfly
MK, Thanks

Re: Im New, And I Need Some Help.

Posted: Thu Jun 25, 2009 9:09 pm
by mjau
Don't waaaanna keep this maaail.

...Cha.