+1 vote

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?

Godot version 3.4.2
in Engine by (40 points)

This is "Bullet" ?

If this scene is a bullet scene, it enters as "var numbers = false" every time it enters the scene.

Essentially, yes, how do I fix that then?

Should it be "false or true" every time it enters the scene, or must it be "false or true" when it enters a "Area"?

When it enters an "Area"

See the answer section here. Do you know how to do it?

https://godotengine.org/qa/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 "

It fixed it, thanks!

1 Answer

0 votes
Best answer

You are welcome

by (656 points)
selected by
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 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 webmaster@godotengine.org with your username.