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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Lovingsoul1337
Citizen
Posts: 53
Joined: Fri Feb 21, 2020 1:26 pm

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

Post 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 !
yal2du
Prole
Posts: 42
Joined: Wed Oct 13, 2021 5:41 pm

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

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests