0 votes

I am sitting 12th hour on this ridicolous error.

There is an Enemy class. Pincher scene inherits from it, and there are 3 different colored Pinchers, being different form each other by exported values.
Enemy scene has "Stats" class scene, collecting exported statistics and making various calculation. Every Pincher has it, as it comes from inherited Enemy.

Stats class is called once on _ready() to iterate through all statistics and multiply it by Pinchers level. What happens is :

When 1 Pincher is instanced calculkation works fine.
When 2 THE SAME Pinchers are instanced calculation loop goes 2 times, but only for second Pincher
When 2 different Pinchers are spawned calculations go well
When 3 and more THE SAME pinchers are spawned calculations go X times for every of them, where X is number of instances
When endless amount of BLUE pinchers is spawned claculations go fine, this is the only one immune to this error, but there is nothing different about him, axcept for color, at leat I can't find it.

When spawning multiple instances of different pinchers it is also easily seen in remote, that their statistics are multiplied proportionally to their instances amount on the screen, exept for blue one, which is perfect.

Anyone has idea what may be responsible for this ? Does it make You think of something ? I made sure underscored ready is used. Is there some gimmick about classess I don't know ? Any help appreciated

Godot version godot 3.2 stable
in Engine by (7,753 points)

Could you show us the code? Just paste it here and format it.

Thank You for your interest !
I have determined, that it is not about double calculations loop, but about next Pincher using previous Pinchers calculated statistics as its base, and so on. Here I am pasting code :

Pinchers ready :

func _ready():
  $Stats.scalestats(lvl)

Leading to mentioned STATS class :

func scalestats(lvl):
#print(stablestatistics)
for key in stablestatistics.keys():
    setstablestat(key,stablestatistics[key] *lvl)
get_parent().health = currenttotal["maxhealth"]

func setstablestat(stat,amount):
stablestatistics[stat] += amount
stabletotal[stat] += amount
setcurrentstat(stat,amount)

func setcurrentstat(stat,amount):
    currentstatistics[stat] += amount
    currenttotal[stat] += amount
    #print(stat,amount)
    updatecalc()

func updatecalc():
currenttotal["mindmg"] = int(stabletotal["mindmg"] *( (currentstatistics["strength"] + 100)/100))
currenttotal["maxdmg"] = int(stabletotal["maxdmg"] *( (currentstatistics["strength"] + 100)/100))
currenttotal["critchance"] = stabletotal["critchance"] + currentstatistics["dexterity"]/100.0 + currentstatistics["luck"]/100.0
currenttotal["maxhealth"] = stabletotal["maxhealth"] + currentstatistics["vitality"] * 5.0
Autoload.luck = currenttotal["luck"]
currenttotal["maxmana"] = stabletotal["maxmana"] + currentstatistics["intellect"]*5.0
if get_parent().has_method("currentfield"): 
    Autoload.emit_signal("statsupdated",stabletotal,currenttotal)

Looks intimidating but these are just hierarchized subroutines, calculations must be done in order, since statistics depend on each other on different levels. Problem lies in mentioned "stablestatistics", highest hierarchy diciotnary. Print in 2nd line shows that starting stablestatistics for every next instance come from former instance. Pinchers have in export{S:10,I:7,D:5}, they all are level 6. First pincher ends correctly with {S:70,I:49,D:35}, next one {S:490,I:340,D:240}, and so on.

The only differences between Pinchers are in exported stablestatistics. But error occured even if I made them have the same exported values. Maybe STATS onready caclculation will also be helpful, this happens before Pinchers are ready and call scalestats :

func _ready():


for dict in [currentstatistics,currentaffinities,currentmisc,currentresists,currentvarious,currentimmunities]:
    for key in dict.keys():
        currenttotal[key] = dict[key]
for dict in [stablestatistics,stableaffinities,stablemisc,stableresists,stablevarious,stableimmunities]:
    for key in dict.keys():
        stabletotal[key] = dict[key]

What this does is gather all exported values into compact dictionaries, stabletotal being base for calculations and currentotal being current values with applied calculations

What makes red and brown pinchers share their "stablestatistics" ? They share it only across scene, like - brown pinchers using brownpinchers stats, red pinchers using red pinchers stats. It is like this variable would reference one dictionary common for whole inherited scene, like something is wrong with property path. I tred using duplicates but it didn;t help.

UPDATE :

I discovered that EXPORT keyword is in fact responsible for this behavior. When variable is exported and updated in runtime it becomes shared among all instances of one scene !! When I turn off export and set stablestatistics in script only - everything works as it should.

Is it a bug, or a gimmick I didn't realize ?

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 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.