Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | iamrifki |
I have a problem regarding inverting booleans in GDScript. I can’t seem to get the boolean inverted properly.
extends RigidBody2D
export var speed = 250
var numbers = false
var modifier_value = ""
func _physics_process(delta):
position += transform.x * speed * delta
func _process(delta):
if numbers == false:
modifier_value = "%"
if numbers == true:
modifier_value = "7"
$Label.text = modifier_value
func _on_Area2D_area_entered(area):
if area.is_in_group("shot"):
numbers = not numbers
print("SHOT")
print(numbers)
print("NOT SHOT")
I want to invert the boolean numbers
because if the shot hits the “modifier” Area2D
it switches from outputting the %
to a 7
and vice-versa.
It doesn’t seem to work here though
NOT SHOT
NOT SHOT
SHOT
True
NOT SHOT
SHOT
True
NOT SHOT
SHOT
True
NOT SHOT
SHOT
True
NOT SHOT
SHOT
True
NOT SHOT
SHOT
True
NOT SHOT
SHOT
True
NOT SHOT
SHOT
True
NOT SHOT
SHOT
True
NOT SHOT
How can I make this work?
This is “Bullet” ?
If this scene is a bullet scene, it enters as “var numbers = false” every time it enters the scene.
ramazan | 2022-02-03 07:54
Essentially, yes, how do I fix that then?
iamrifki | 2022-02-03 08:52
Should it be “false or true” every time it enters the scene, or must it be “false or true” when it enters a “Area”?
ramazan | 2022-02-03 09:05
When it enters an “Area”
iamrifki | 2022-02-03 09:12
See the answer section here. Do you know how to do it?
https://forum.godotengine.org/46994/how-to-emit-signal-from-one-scene-to-another
Don’t adding new scene. you just need to create a script named “Global.gd”.
Add the Global.gd
var numeral = false
///////////
Then access here from the bullet scene and use this instead of "numbers "
ramazan | 2022-02-03 09:31
It fixed it, thanks!
iamrifki | 2022-02-03 11:09