Line has no effect godot 4?
Money = 0 in global.global.gd
Lives = 3
in world gd
func_ready:
if global.Money = 10 ( += also doesn't work, although it would be the better choice).
global.Lives + 1
Test opponent.gd
collision body entered:
if player entered
Game.Money + 10
(This is just a test script to describe the error)
Errors in the test opponent:
Standalone expression (the line has no effect)
Why no effect if it has been defined and can be called anywhere via global?
If you want to use the global `money` variable anywhere, you need to make sure that your `global.gd` script is registered as a single tone (autoload).
In the `world.gd` Script is not correct for the if block. You should use `=` for comparison and `+=` to increase `Lives`, so:
In the `Testgegner.gd` script, the function could look like this:
Make sure that the player body in the game has the name “Player” so that the code works.
..but += does not increase, it leads the
action if it is higher or equal to the number, so it only checks those living?
in global lives += 1
Excuse the confusion. The `+=` character is a link operator that increases the variable on the left side by the value on the right side. In your case, `global.Lives += 1` will increase the `Lives` variable by 1.
If you write `if global.Money == 10:`, the code will only be executed in the if block if `money` is exactly 10. If this applies, `global.Lives += 1` is executed, which increases the number of `Lives` by 1.
The `if` instruction only checks the value of `money`, and if this is 10, then `global.Lives += 1` increases the number of lives by 1.
I don’t know in Godot, but I guess here, as in the vast majority of languages, the result of global.Lives + 1 is calculated and discarded. The line is therefore completely meaningless and should be
to be replaced.
is it right to have in the ready function of the world? I think it fails