#1 script 2 node export var

28 messages · Page 1 of 1 (latest)

calm cipher
#

Hi. So i have one script that controls two castle (p1 - p2)
It has an export variable int for the team they in. (1 or 2)
But somehow its not working.
I tried also tried to change the variable on run like.

If name. P1castle change team =1
If P2castle change team =2

I print out their team on ready and it prints out 1-2
But the resource it generate only goes to player 1 which is controlled by the team int.

Should i instantiate the castles from a script? And not place them on? Or is this what classes for?

How do you do different teams normaly?

lofty harbor
#

humm, that should work

#

it should grab the variable set in the inspector

calm cipher
#

when i look remote i see that the two castle indeed have the correct team

#

func gather_res():
if team ==1:
Global.Player1_gold += gold_amount
Global.Player1_wood += wood_amount
if team ==2:
Global.Player2_gold += gold_amount
Global.Player2_wood += wood_amount
else:
pass

#

but this code i dont know why but only works for team =1
team 1 will get double res

#

if i write team 1 for the player2_gold it then gives the gold to player 2

lofty harbor
#

did you try to print the team variable in that function?

calm cipher
#

oh the timer signal can be the problem

lofty harbor
#

(You should consider creating a Resource to store those values. You would not need to duplicate variables for each team.)

#

you could even assign the Resource straight to the castle instead of the team number.

calm cipher
lofty harbor
#

and have the team be part of the team data resource

#

why is the timer the problem?

calm cipher
#

okay i will look into resources i didnt use them yet

#

when i print team it prints team 1 twice although i look into the remote and i see the exported variable is 1 and 2

lofty harbor
#

is super simple to create

class_name TeamData
extends Resource

@export var team:int = 0
@export var wood:int = 0
@export var gold:int = 0
calm cipher
#

and i dont change it anywhere

lofty harbor
#

that is weird

#

is the signal maybe connected to the same node?

calm cipher
#

yeah that is the problem

#

i copied over the timer so its still conected to just the p1

lofty harbor
#

connect in your castle script

#

so you don't have to worry

calm cipher
#

works like a charm!

#

thank you very much! 😄