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

Unexpected behaviour when processing more than one entity. #32

Open
vimnux opened this issue Feb 9, 2025 · 0 comments
Open

Unexpected behaviour when processing more than one entity. #32

vimnux opened this issue Feb 9, 2025 · 0 comments

Comments

@vimnux
Copy link

vimnux commented Feb 9, 2025

local ent1 = { foo = true }
local ent2 = { bar = 1 }

local tiny = require("tiny")
local world = tiny.world()

tiny.addEntity(world, ent1)
tiny.addEntity(world, ent2)
tiny.refresh(world)

local sys = tiny.processingSystem({ isSystem = true })
sys.filter = tiny.requireAny("foo", "bar")

function sys:process(e)
  print("foo is: " .. tostring(e.foo))
  print("bar is: " .. tostring(e.bar) .. "\n")
end

tiny.addSystem(world, sys)

local filter = tiny.requireAll("isSystem")
tiny.update(world, 1, filter)

Results in:

foo is: true
bar is: nil

foo is: nil
bar is: 1

Instead of the expected:

foo is: true
bar is: 1

The issue also occurs when processing 2 entities after selecting them with:

tiny.setSystemIndex(world, system)

or:

tiny.requireAll (...)

Is there a "tiny-ecs way" to get the expected behavior ?

Or do I have to add checks for nill values like:

local ent1 = { foo = true }
local ent2 = { bar = 1 }

local tiny = require("tiny")
local world = tiny.world()

tiny.addEntity(world, ent1)
tiny.addEntity(world, ent2)
tiny.refresh(world)

local sys = tiny.processingSystem({ isSystem = true })
sys.filter = tiny.requireAny("foo", "bar")

function sys:process(e)
  if e.foo ~= nill then
    print("foo is: " .. tostring(e.foo))
  end
  if e.bar ~= nil then
    print("bar is: " .. tostring(e.bar) .. "\n")
  end
end

tiny.addSystem(world, sys)

local filter = tiny.requireAll("isSystem")
tiny.update(world, 1, filter)

To get the values of components "foo" and "bar" as:

foo is: true
bar is: 1

I encountered the issue in both the latest git and the 1.3-3 release.

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