Teardown-Issue-Tracker-Maintainers / Teardown-Issue-Tracker

A public repo for the community to track issues/bugs/feature requests in Teardown.
11 stars 6 forks source link

[Bug] Impossible to access elements from nested scripts #555

Closed FlorentP42 closed 2 months ago

FlorentP42 commented 2 months ago

Describe the bug

So there might be several issues into one here but the main issue is: if you have nested scripts, then all the elements inside the inner script will not be found when calling global Find()/FindAll() functions in the outer script.

If this is a feature then, please change it or give an additional parameter to the Find() functions to handle that case... It is a real pain to have a script browsing all elements from the whole scene in order to find back one of its own sub-elements when the Find() functions are supposed to do precisely that by default but you notice some elements are missing...

Steps to reproduce the behavior

  1. Save the following as prefab.xml in your mod root dir:
    <prefab version="1.3.0">
    <group name="instance=MOD/prefab.xml" pos="0.0 0.0 0.0" rot="0.0 0.0 0.0">
    <script pos="-0.1 -0.1 -0.1" file="MOD/script1.lua">
      <group prop0="texture=12 0.5">
    <body tags="body nested1" pos="0.1 1.2 0.1" dynamic="true">
          <vox tags="shape nested1" pos="-0.05 1.0 0.0" rot="0 90 0" file="MOD/dummy.vox"/>
        </body>
        <script pos="-0.1 -0.1 -0.1" file="MOD/script2.lua">
          <body tags="body nested2" pos="0.1 1.2 0.1" dynamic="true">
            <vox  tags="shape nested2" pos="-0.05 1.0 0.0" rot="0 90 0" file="MOD/dummy.vox"/>
          </body>
        </script>
      </group>
    </script>
    </group>
    </prefab>
  2. Save the following as script1.lua in your mod root dir:
    function init()
    DebugPrint("script1")
    local bodies = FindBodies()
    DebugPrint("BodiesFound="..#bodies)
    local shapes = FindShapes()
    DebugPrint("ShapesFound="..#shapes)
    local bodiesByTag = FindBodies("body")
    DebugPrint("BodiesFoundByTag="..#bodiesByTag)
    local shapesByTag = FindShapes("shape")
    DebugPrint("ShapesFoundByTag="..#shapesByTag)
    end
  3. Save the following as script2.lua in your mod root dir:
    function init()
    DebugPrint("script2")
    local bodies = FindBodies()
    DebugPrint("BodiesFound="..#bodies)
    local shapes = FindShapes()
    DebugPrint("ShapesFound="..#shapes)
    local bodiesByTag = FindBodies("body")
    DebugPrint("BodiesFoundByTag="..#bodiesByTag)
    local shapesByTag = FindShapes("shape")
    DebugPrint("ShapesFoundByTag="..#shapesByTag)
    end
  4. Take any valid vox file and put in your mod root dir as dummy.vox.
  5. Add this prefab to spawn.txt.
  6. Run the mod and spawn the prefab.
  7. Notice that script1.lua only finds the entites tagged nested1 and script2.lua only those tagged nested2.

Expected behavior

script1.lua also finds the entities tagged nested2.

Environment

Additional context

Extracted from #345 as the topic discussed in that other ticket ended up being quite different than the main issue.

Gregory-Gregory commented 2 months ago

@FlorentP42 hi!

Thank you for opening a new discussion for this one. To avoid misunderstanding, this is still relevant in the 1.5.4?

FlorentP42 commented 2 months ago

Honestly I did not try it again since the update, but I doubt this would have changed without any mention to it in a patch note? If I can find some time to test it again in the latest update I will let you know :)

FlorentP42 commented 2 months ago

Well, I could not reproduce it with the example above in 1.5.4

So either it was fixed or the issue I had with the larger prefab file was not correctly reproduced by this example...

In any case I will close this ticket assuming it was fixed ^^