bug: Container.removeChild does not work with strings #108

Closed
opened 2024-04-16 09:33:04 +08:00 by WorldChallenge1 · 3 comments
WorldChallenge1 commented 2024-04-16 09:33:04 +08:00 (Migrated from github.com)

Describe the bug

When trying to use the function removeChild with an ID of an element this gives an error

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://basalt.madefor.cc/#/objects/Container/removeChild
  2. Copy the example
  3. Run it
  4. See error in the 1st screenshot

Expected behavior

The specified children of the container gets removed.

Probable cause

The problems seems to be that when passing a string it tries to call the method getName() which is a method of basalt Object's (2nd screenshot)

Screenshots

Code_gCAWxLm3vT
brave_BbiDgzqQDV

Checklist

[x] I am running the latest version.

**Describe the bug** When trying to use the function removeChild with an ID of an element this gives an error **To Reproduce** Steps to reproduce the behavior: 1. Go to https://basalt.madefor.cc/#/objects/Container/removeChild 2. Copy the example 3. Run it 4. See error in the 1st screenshot **Expected behavior** The specified children of the container gets removed. **Probable cause** The problems seems to be that when passing a string it tries to call the method getName() which is a method of basalt Object's (2nd screenshot) **Screenshots** ![Code_gCAWxLm3vT](https://github.com/Pyroxenium/Basalt/assets/49007278/dd884f2e-a06d-4627-a508-12d8c4766ab9) ![brave_BbiDgzqQDV](https://github.com/Pyroxenium/Basalt/assets/49007278/f9ee130c-2da1-4a93-972f-d22345dd9ac1) **Checklist** [x] I am running the latest version.
WorldChallenge1 commented 2024-04-16 12:54:26 +08:00 (Migrated from github.com)

Also when passing the object it does work

local basalt = require("basalt")

local main = basalt.createFrame()
local container = main:addFrame("container")
local button = container:addButton("removableButton")
    :setPosition(2, 2)
    :setText("Remove me")

main:addButton()
    :setPosition(2, 4)
    :setText("Remove the button above")
    :onClick(function()
        local removed = container:removeChild(button)
        if removed then
            basalt.debug("Button removed!")
        else
            basalt.debug("Button not found!")
        end
    end)

basalt.autoUpdate()

Code_7nCkHqcEcI

In a related note Flexbox seems to not work at all either way

local basalt = require("basalt")

local main = basalt.createFrame()
local container = main:addFlexbox("container")
local button = container:addButton("removableButton")
    :setPosition(2, 2)
    :setText("Remove me")

main:addButton()
    :setPosition(2, 4)
    :setText("Remove the button above")
    :onClick(function()
        local removed = container:removeChild("removableButton")
        if removed then
            basalt.debug("Button removed!")
        else
            basalt.debug("Button not found!")
        end
    end)

basalt.autoUpdate()

Code_68sACyIajk

Using the object it doesn't crash but it is unable to find the child

local basalt = require("basalt")

local main = basalt.createFrame()
local container = main:addFlexbox("container")
local button = container:addButton("removableButton")
    :setPosition(2, 2)
    :setText("Remove me")

main:addButton()
    :setPosition(2, 4)
    :setText("Remove the button above")
    :onClick(function()
        local removed = container:removeChild(button)
        if removed then
            basalt.debug("Button removed!")
        else
            basalt.debug("Button not found!")
        end
    end)

basalt.autoUpdate()

Code_ayYKcZ8HdS

Also when passing the object it does work ```lua local basalt = require("basalt") local main = basalt.createFrame() local container = main:addFrame("container") local button = container:addButton("removableButton") :setPosition(2, 2) :setText("Remove me") main:addButton() :setPosition(2, 4) :setText("Remove the button above") :onClick(function() local removed = container:removeChild(button) if removed then basalt.debug("Button removed!") else basalt.debug("Button not found!") end end) basalt.autoUpdate() ``` ![Code_7nCkHqcEcI](https://github.com/Pyroxenium/Basalt/assets/49007278/0fecb2c5-8316-44f0-a240-61bd82d04895) In a related note Flexbox seems to not work at all either way ```lua local basalt = require("basalt") local main = basalt.createFrame() local container = main:addFlexbox("container") local button = container:addButton("removableButton") :setPosition(2, 2) :setText("Remove me") main:addButton() :setPosition(2, 4) :setText("Remove the button above") :onClick(function() local removed = container:removeChild("removableButton") if removed then basalt.debug("Button removed!") else basalt.debug("Button not found!") end end) basalt.autoUpdate() ``` ![Code_68sACyIajk](https://github.com/Pyroxenium/Basalt/assets/49007278/1308f23c-c9c5-4eca-b123-2a52249985ba) Using the object it doesn't crash but it is unable to find the child ```lua local basalt = require("basalt") local main = basalt.createFrame() local container = main:addFlexbox("container") local button = container:addButton("removableButton") :setPosition(2, 2) :setText("Remove me") main:addButton() :setPosition(2, 4) :setText("Remove the button above") :onClick(function() local removed = container:removeChild(button) if removed then basalt.debug("Button removed!") else basalt.debug("Button not found!") end end) basalt.autoUpdate() ``` ![Code_ayYKcZ8HdS](https://github.com/Pyroxenium/Basalt/assets/49007278/608c3284-e056-48a6-b155-647fda7a9da0)
NoryiE commented 2024-04-17 01:13:31 +08:00 (Migrated from github.com)

Hey, i think it is fixed now. I didn't try the flexbox. Thank you for the report!

Hey, i think it is fixed now. I didn't try the flexbox. Thank you for the report!
WorldChallenge1 commented 2024-04-17 02:18:25 +08:00 (Migrated from github.com)

Downloaded the source and tried all the examples and they all worked without problems. Thanks!

Downloaded the source and tried all the examples and they all worked without problems. Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: GitHub/Basalt#108
No description provided.