#why are all my player slots in sync?

40 messages · Page 1 of 1 (latest)

tacit token
#

I can't figure out why my player alot scenes are all in sync
They are different instances but when I click on one it updates the other...

@tool extends Control

@export_range(0,3) var id   := 0

func _ready():
    Game.player_changed.connect(func(player):
        if player.id != id: return
        _update(player))
    Game.player_opened .connect(func(player):
        if player.id != id: return
        if $Animator.is_playing():
            await $Animator.animation_finished
        $Animator.play("open"))
    Game.player_closed .connect(func(player):
        if player.id != id: return
        if $Animator.is_playing():
            await $Animator.animation_finished
        $Animator.play("close"))
        
func _update(player:Player)->void:
    var text_x = player.mode * 16
    var text_y = player.id   * 8  + 96
    $Background/Text.texture.region.position.x = text_x
    $Background/Text.texture.region.position.y = text_y
    
    var card_x = player.team * 32
    $Background/Card.texture.region.position.x  = card_x
    
    var door_x = player.id   * 32
    $Foreground/LDoor.texture.region.position.x = door_x
    $Foreground/RDoor.texture.region.position.x = door_x
func is_basic_input(event:InputEvent)->bool:
    if event is InputEventMouseButton:
        if event.pressed && event.button_index == MOUSE_BUTTON_LEFT:
            return true
            
    if event is InputEventScreenTouch:
        if event.pressed:
            return true
            
    if event is InputEventAction:
        if event.is_action("ui_accept"):
            return true
    return false
    
func _on_door_gui_input(event):
    if is_basic_input(event):
        Game.get_player(id).mode = 1
func _on_text_gui_input(event):
    if is_basic_input(event):
        Game.get_player(id).mode = wrapf(Game.get_player(id).mode + 1, 0, 3)
func _on_card_gui_input(event):
    if is_basic_input(event):
        Game.get_player(id).team = wrapf(Game.get_player(id).team + 1, 0, 4)
        
#
extends Node

signal player_changed(player:Player)
signal player_opened (player:Player)
signal player_closed (player:Player)
@export var p1 : Player: 
    set(v):
        if  p1 != v:
            p1  = v
            p1.changed.connect(func(): player_changed.emit(p1))
            p1.opened .connect(func(): player_opened .emit(p1))
            p1.closed .connect(func(): player_closed .emit(p1))
@export var p2 : Player:
    set(v):
        if  p2 != v:
            p2  = v
            p2.changed.connect(func(): player_changed.emit(p2))
            p2.opened .connect(func(): player_opened .emit(p2))
            p2.closed .connect(func(): player_closed .emit(p2))
@export var p3 : Player:
    set(v):
        if  p3 != v:
            p3  = v
            p3.changed.connect(func(): player_changed.emit(p3))
            p3.opened .connect(func(): player_opened .emit(p3))
            p3.closed .connect(func(): player_closed .emit(p3))
@export var p4 : Player:
    set(v):
        if  p4 != v:
            p4  = v
            p4.changed.connect(func(): player_changed.emit(p4))
            p4.opened .connect(func(): player_opened .emit(p4))
            p4.closed .connect(func(): player_closed .emit(p4))

func _init():
    p1 = Player.new()
    p2 = Player.new()
    p3 = Player.new()
    p4 = Player.new()
    p1.id = 0
    p2.id = 1
    p3.id = 2
    p4.id = 3
    

func get_player(id:int)->Player:
    match id:
        0: return p1
        1: return p2
        2: return p3
        3: return p4
        _: return null```
#
class_name Player extends Resource

signal opened()
signal closed()

@export_range(0,3) var id   := 0: 
    set(v):
        if  id != v:
            id  = v
            emit_changed()
@export_range(0,3) var team := 0: 
    set(v):
        if  team != v:
            team  = v
            emit_changed()
@export_range(0,2) var mode := 0: 
    set(v):
        if  mode != v:
            if mode == 0 && v != 0: opened.emit()
            if mode != 0 && v == 0: closed.emit()
            mode  = v
            emit_changed()
#

The only thing I can think of is that I am sharing signals between players but that shouldn't matter because I am checking if the id is diffrent and returning

abstract niche
#

that'd cause that behavior, because it'd basically be a static resource and never be instantiated with separate values

tacit token
#

do I need init for resources?

abstract niche
#

yup!

tacit token
#

oh ok thankyou

#

let me see if that works

abstract niche
#

make sure anything that needs to be saved/loaded/etc. with the resource is passed in as an argument, and the arguments HAVE to be optional (with default values) as it shows there

tacit token
#

so it can't be a empty constructor?

abstract niche
#

it can, but it'll set everything to default every time it's instantiated (or whatever you set it to read inside the constructor)

tacit token
#

ya its still doing the same thing

abstract niche
#

if you want it to read the values from an individual "saved" resource (whether it's a file or whatever, even in data, loading, etc.) it'll need the args

#

ah well. was hoping that'd be it, sorry KEKW

#

from there my next guess was the signals not being individual to the instance, but I'm not sure how to help you out with that one (you kinda already addressed that you checked it and it wasn't the issue)

tacit token
#

oh

#

would a autoload do this?

#

my Game class is a autoload

abstract niche
tacit token
#

I have 4 player variables in the autoload

#

so it shouldn't be a issue

#

ok I think it has something to do with bugged textures

#

I just removed all code linking the the Game autoload and the Player resource

tacit token
#

what does it mean if Members and the properties of the script is exported twice in the remote inspector?

#

maybe thats the problem

#

I might have just broke godot

#

I slimmed it down to just this...

#
@tool extends Control

@export_range(0,3) var id   := 0
@export_range(0,3) var team := 0
@export_range(0,2) var mode := 0
var closed := true
func _process(delta:float)->void:
    var text_x = mode * 16
    var text_y = id   * 8  + 96
    $Background/Text.texture.region.position.x = text_x
    $Background/Text.texture.region.position.y = text_y
    
    var card_x = team * 32
    $Background/Card.texture.region.position.x  = card_x
    
    var door_x = id   * 32
    $Foreground/LDoor.texture.region.position.x = door_x
    $Foreground/RDoor.texture.region.position.x = door_x
abstract niche
#

but in this case it might not be that

tacit token
#

I don't know where those signals are comeing from

#

I can't even remove signals

#

there is no other scene for it to inherit from

tacit token
#

I reported it as a bug