#Split-screen multiplayer... with respawning players

3 messages · Page 1 of 1 (latest)

humble coyote
#

I'm trying to make a splitscreen 1v1 game. To test the respawning of the players, I was going to start the scene without any players in it (I would instantiate them via code later), but it throws an error.
I know that the error is to do with there being no players to follow. So, is there a technique I can use for this kind of problem? Or is this just what I get for following tutorials without changing the code? 😭

#

fyi, this is the whole script:


#Multiplagtyer
#Code from https://www.youtube.com/watch?v=tkBgYD0R8R4

@onready var players := {
    "1": {
        viewport = $"HBox/SubViewportContainer/SubViewport",
        camera = $"HBox/SubViewportContainer/SubViewport/Camera2DP1",
        player = $"HBox/SubViewportContainer/SubViewport/Stage/Player1",
    },
    "2": {
        viewport = $"HBox/SubViewportContainer2/SubViewport",
        camera = $"HBox/SubViewportContainer2/SubViewport/Camera2DP2",
        player = $"HBox/SubViewportContainer/SubViewport/Stage/Player2",
    },
}

func _ready():
    players["2"].viewport.world_2d = players["1"].viewport.world_2d
    for node in players.values():
        var remote_transform := RemoteTransform2D.new()
        remote_transform.remote_path = node.camera.get_path()
        node.player.add_child(remote_transform)
#

it's because player is defined up there, and i probably need to make this code somehow toggle off when no players are detected