Page 1 of 1

Love with Coroutine Window say's "Not Responding."

Posted: Sat Jun 17, 2023 10:19 pm
by Lovingsoul1337
Can someone tell me what this could be ? I tried so much stuff now and not 1 single thing worked.

The command prompt is printing the coord's but the love window doesn't show anything and just say "not responding".

Code: Select all


[b]main.lua[/b]

local she = require("she")
local She = she.new("She", 100, 200)
She:start()

local image

function love.load()
    love.graphics.setBackgroundColor(255, 255, 255)
    image = love.graphics.newImage("assets/She/She.png")
end

function love.update(dt)
    She:update()  -- Call the update function of the She instance
end

function love.draw()
    love.graphics.draw(image, She.x, She.y)
end

// put your code here    

[b]She.lua[/b]

local she = {}

local she_meta = {
    __index = she
}

function she.new(name, x, y)
    local instance = {
        sheActive = false,
        name = name,
        x = x,
        y = y,
        updateCoroutine = nil
    }

    setmetatable(instance, she_meta)

    function instance:start()
        self.sheActive = true
        self.updateCoroutine = coroutine.create(self.update)
        coroutine.resume(self.updateCoroutine, self)
    end

    function instance:move()
        local randomNumberX = math.random(-1, 1)
        local randomNumberY = math.random(-1, 1)

        self.x = self.x + randomNumberX
        self.y = self.y + randomNumberY
    end

    function instance:update()
        while self.sheActive do
            self:move()
            print(self.x, self.y)
        end
    end

    return instance
end

return she
    
thanks in advance !

Re: Love with Coroutine Window say's "Not Responding."

Posted: Sun Jun 18, 2023 12:17 am
by yal2du

Code: Select all

    function instance:update()
        while self.sheActive do
            self:move()
            print(self.x, self.y)
        end
    end
looks like an infinite loop. also there is no yield /resume like you'd need with a coroutine. here is link to lua coroutine docs

https://www.lua.org/manual/5.1/manual.html#5.2

that said, i don't think you'd need a coroutine since you are calling instance:update directly in love.update