0 votes

I am creating a multiplayer dice game.
I have a tab panel in which I add all players' scorecards as tabs. For the current player I want to add a panel to the left showing its own scorecard.

This is the code that adds a player and with that adds a new scorecard to the tab pane.

sync func add_player(id, name=""):
    _players.append(id)
    #var _newPlayer = Player.new(id, name)
    #var _newPlayer = preload("res://scene/Player.tscn")
    #var newPlayer = _newPlayer.instance()
    var newplayer = KwixxPlayer.new()
    newplayer.id = id
    newplayer.name  = name
    _playersDict[id] = newplayer
    if name == "":
        name = "unknown"
    var _newPanel = PanelContainer.new()
    _newPanel.set_name(newplayer.name)
    _newPanel.set_size(Vector2(200, 200),false)  
    _tablist.add_child(_newPanel)
    var _newScorecard = preload("res://scene/Scorecard.tscn")
    var newScorecard = _newScorecard.instance()
    newScorecard.set_name(str(id))
    newScorecard.find_node("scorecard").set_expand(true)
    newScorecard.find_node("scorecard").set_stretch_mode(5)
    scorecards[id] = newScorecard
    _newPanel.add_child(newScorecard)

Then for the current user, in this debug scenario this, should add the players own scorecard:

func start():
    set_turn(0)
    loaddice()
    if !is_network_master():
        for peer in _players:
            rpc_id(peer, "_show_own_scorecard(id)", peer)
    elif is_network_master():
        var _owncard = scorecards[1]
        _owncard.set_name("mycard")
        _owncardpanel.add_child(_owncard)
        print_tree()
        pass

It gives the error "E 0:00:02.865 add_child: Can't add child 'mycard' to 'leftpanel', already has a parent 'ffff'." ('ffff' is what I typed as test name in debug run)

I don't understand, because there is a tab that has that name, but it is on another place in the tree and not a parent. Also I set the name to "mycard" to avoid having two same node names.

This is the tree it printed when running:

.
VBoxContainer
VBoxContainer/HBoxContainer
VBoxContainer/HBoxContainer/leftpanel
VBoxContainer/HBoxContainer/SubVBoxContainer
VBoxContainer/HBoxContainer/SubVBoxContainer/Action
VBoxContainer/HBoxContainer/SubVBoxContainer/Label
VBoxContainer/HBoxContainer/SubVBoxContainer/Tabs
VBoxContainer/HBoxContainer/SubVBoxContainer/Tabs/ffff
VBoxContainer/HBoxContainer/SubVBoxContainer/Tabs/ffff/mycard
VBoxContainer/HBoxContainer/SubVBoxContainer/Tabs/ffff/mycard/scorecard
VBoxContainer/HBoxContainer/SubVBoxContainer/Tabs/ffff/mycard/scorecard/BlueButtonContainer
VBoxContainer/HBoxContainer/SubVBoxContainer/Tabs/ffff/mycard/scorecard/BlueButtonContainer/CheckBox2Blue
VBoxContainer/HBoxContainer/SubVBoxContainer/Tabs/ffff/mycard/scorecard/BlueButtonContainer/CheckBox2Blue/check

(it goes on but that's not relevant)

Could someone explain what I'm doing wrong here? Thanks in advance!

Godot version v.3.2.3
in Engine by (17 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.