0 votes

first thank you for read this question.
why when i change one variable value in resource, the other variable also change?
when i set my atk value, my dex value also change.
when i remove this two, it did't change my dex value. but why this two change my dex value??
This two value in func set_atk_list( )

min_atk_list[1] = new_value
max_atk_list[1] = new_value

i do try use setget, still get same result
dex should be value should be zero.
the print resultresTest dex = 999 || atk = 77777777777 || dex_list[1] = 77777777777

this my resource

class_name ResTest_res extends Resource

export var atk_list     : Array = [0,0,0,0,0,0] 
export var min_atk_list : Array = [0,0,0,0,0,0] 
export var max_atk_list : Array = [0,0,0,0,0,0] 
var _atk                : int = 0# calculate all atk list
var _min_atk            : int = 0
var _max_atk            : int = 0
# dex  ################################
export var dex_list     : Array = [0,0,0,0,0,0] 
const dex_cap           : int = 999
var _dex                : int = 0

###########################################
## set atk ################################
func set_atk_list(  ):
    var new_value : int = 0
    for st in atk_list:
        new_value += st
    #set min and max atk list
    min_atk_list[1] = new_value
    max_atk_list[1] = new_value
    _atk = new_value

###########################################
## set min max atk ########################
func set_min_atk_list( ):
    var new_value : int = 0
    for st in min_atk_list:
        new_value += st
    _min_atk = new_value

func set_max_atk_list( ):
    var new_value : int = 0
    for st in max_atk_list:
        new_value += st
    _max_atk = new_value

#dex ##########
func set_dex_list(  ):
    var new_value : int = 0
    for st in dex_list:
        print( st, ">>>>>")
        new_value += st
        print( st, "<><>")
    if new_value > dex_cap:
        new_value = dex_cap
    # set dex value
    _dex = new_value

and this my node code

extends Node2D

var stats : ResTest_res = ResTest_res.new()

func _ready() -> void:
    stats.atk_list[0]  = 77777777777
    stats.set_atk_list()


    stats.dex_list[0] = 0
    stats.set_dex_list()
    print(name," dex = ", stats._dex, " || atk = ", stats._atk, " || dex_list[1] = ", stats.dex_list[1] )
Godot version 3.5
in Engine by (419 points)
edited by

1 Answer

+1 vote
Best answer

You must have copied 6 zeroes array from attack slot to dex slot in editors export label once, and forgot about it. Editor still treats it as a shared resource. Clear entries of export values in editor. If this doesn't help, remove export keyword from code, reset editor, and introduce it again.

by (7,742 points)
selected by

thanks, i check if i copy, but i did't. i write new code, it still change all other array value.
the only way to fix is like you say remove export.

resource code

class_name ResTest_res extends Resource
export var A : Array = [0,0,0,0,0,0] 
export var B : Array = [0,0,0,0,0,0] 
export var C : Array = [0,0,0,0,0,0] 

node code

extends Node2D

var stats : ResTest_res = ResTest_res.new()

func _ready() -> void:
    stats.A[1] = 9999
    print("A = ",stats.A)
    print("B = ",stats.B)
    print("C = ",stats.C)

print result

A = [0, 9999, 0, 0, 0, 0]
B = [0, 9999, 0, 0, 0, 0]
C = [0, 9999, 0, 0, 0, 0]

I had this kind of export bug once, but it happened when multiple instances of inherited scene were setting their stats at the same time. It occured, that Godot treats exported arrays and dictionaries as a resource shared by all instances of inherited scenes.

What about You, is only one instance calling this code above ?

yes, my player and mob also use this resource, when player and all mob in same map, the stats will combine together..
example :
my player stats.dex = [10,0,0,]
and when i change my mob stats in mob node.
my mob stats.atk[1]= 3
- my player stats.dex become like this [10,3,0,0]

in player and mob ready funtion, i make stats = newStats.new(). they should not be share.
but they share the value when i have export... do you know any idea how to fix it?

I hoped they would eradicate this bug in 3.5

This is propably bug of scene inheritance. Player and mob share the same parent scene ?
If it is true, You may just delete stats node from parent scene, and child it manually for every inheritor. Let me know if it works.

player and mob did't inherit same scene. i make 2 complete different scene.
then in both scene, i make var stats : resource then in ready i code like this stats = newStats.new().

then i instance bot player and mob in Map_scene/ Ysort

so from start i did't share scene.
if you meant something like bellow , then i did't share
player node = extends customSceneEntity
mob node = extends customSceneEntity

i make it like this
player node = class_name PlayerClass extends KinematicBody2D
player code:

var stats : EntityStatBase
func _ready() -> void:
    stats = EntityStatBase.new()

mob node = class_name MobClass extends KinematicBody2D
mob code:

var stats : EntityStatBase
func _ready() -> void:
    stats = EntityStatBase.new()

I am sorry than, it really is a total bug of export keyword.
I never repaired mine issue with this, I just erased export and circled around the problem somehow

its ok, thanks for help

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 Frequently asked questions and 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 [email protected] with your username.