Hi @TwistedTwigleg , sry for confusing comment :|
No reason to apologize! I just had a hard time figuring out what has happening, that's all :smile:
i managed to call my variables, but the problem is that it seems it returns default value..
Hmm, well there could be two different things at work here.
One thing that could be causing the issue is the order in your scene tree. For example, suppose you have the following nodes in the following order in a scene.
-| Node_1
-| Node_2
And let's say both have a variable called foo which is set to 4 by default, but in the _ready function, each node changes foo to 2. Finally, let's say you are printing both Node_1 and Node_2's foo variable in each _ready function
(using code like print("Node_1 print statement: Node_1.foo = ", self.foo, ", Node_2.foo = ", get_parent().get_node("Node_2").foo) for Node_1 and similar code for Node_2)
The output from the example would look like this:
Node_1 print statement: Node_1.foo = 2, Node_2.foo:4
Node_2 print statement: Node_1.foo = 2, Node_2.foo:2
Because of how Godot executes _ready, when Node_1 prints both foo values, for Node_2 the value is still in it's default state. This is because Godot calls _ready going down the scene tree, and because Node_1 is above Node_2 in the scene tree, Node_2's _ready function has not been called yet.
So it could be that when you are accessing score1 and score2 from MainGame, _ready has not been called yet in MainGame because it is lower in the scene tree.
Another thing that could be causing the issue is how you have your if statements setup. In the code for checking score, you are checking to see if score1 is greater than score2 (using if score1>score2) and if it does you are setting the text saying that player 1 wins.
However, if score1 is not greater than score2, you are setting the text saying that player two wins.
Because you are using else, this means any time the if statement (score1 being higher than score2) is false, it is going to set the text to show that player 2 wins. This means both score2 being higher than score1 will set the text to show player 2 has won (because score2 is more than score1) and when both scores are equal it will set the text to show player 2 has won (because score1 is not greater than score2, but rather they are equal).
Thankfully the fix is really simple. You just need to replace _ready with the following code:
func _ready():
if score1>score2:
get_node("WhoWin").set("text","PLAYER ONE WINS")
elif score<score2:
get_node("WhoWin").set("text","PLAYER TWO WINS")
else:
pass; "Equal scores!"
Hopefully this helps!
Edit: Just saw your comment (we must have been writing at the same time :lol: )
No worries, you were not bothering me. Glad you figured it out :)