Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate in console gives error "!! Attempted to continue while not in a prompt" #104

Open
paulbatum opened this issue Nov 23, 2023 · 1 comment

Comments

@paulbatum
Copy link

I have the debugger up and running and everything is working fine in terms of breakpoints and using the console, but when I try to select this code in a lua file and use Debug: Evaluate in Console, it works the first time but fails the second time.

-- Function to get detailed entity count for a specific chunk
local function getEntityCountForChunk(surface, chunkPosition)
    local entitiesInfo = {}
    local entityCounts = {}
    local chunkSize = 32 -- Size of a chunk in tiles
    local chunkArea = {
        {chunkPosition.x * chunkSize, chunkPosition.y * chunkSize},
        {(chunkPosition.x + 1) * chunkSize, (chunkPosition.y + 1) * chunkSize}
    }

    -- Finding all entities in the specified chunk area
    local entities = surface.find_entities(chunkArea)

    -- Counting entities by name and type
    for _, entity in pairs(entities) do
        local identifier = entity.name .. "-" .. entity.type
        if entityCounts[identifier] then
            entityCounts[identifier].count = entityCounts[identifier].count + 1
        else
            entityCounts[identifier] = {name = entity.name, type = entity.type, count = 1}
        end
    end

    -- Converting the counts to a list format
    for _, info in pairs(entityCounts) do
        table.insert(entitiesInfo, info)
    end

    local chunkData = {
        chunk_position = chunkPosition,
        entities = entitiesInfo
    }

    return chunkData
end

return getEntityCountForChunk(game.players[1].surface, {x=-1,y=-1})

First time, it runs successfully and outputs the table and I can inspect it no problem.

Now I just do the same thing again. With same text selected, I do Debug: Evaluate in Console and I get the following error:
!! Attempted to continue while not in a prompt

Things enter a strange state at this point. The game stops responding, as if the debugger had the game paused, but the debugger thinks the game is still running, the pause button doesn't do anything, and I cannot get the game to resume running without a full restart.

Really I'm just looking for a coding flow I can use where I can write code in the editor and evaluate it without having to save and reload the game every time. I thought the eval in console feature would be a good way to do that.

@paulbatum
Copy link
Author

Ahh, I am guessing that this error happens because I'm doing the debug:eval without the game paused. It seems that I need to set a breakpoint first, let the debugger pause, and then I can repeatedly do these evals OK.

It is interesting that the debug:eval never fails the first time I do it when the game is running.

So the next question would be, is the debugger supposed to support doing an eval while the game is running, similar to how it can be done via the game console? If so, I think there is a bug here. If not, I suggest printing a warning and rejecting the eval operation if the game is running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant