0 votes
extends Node

var b : bool = false

func _process(delta):
    if randf() > 0.998:
        b = not b
        print(b)

Expected output:
True
False
True
False
...

Actual output:
a random sequence of True and False

The problem remains when I delete the condiditon "if randf() > 0.998".

Godot version 3.2
in Engine by (16 points)

What do you mean?

I just the tried same:

var b: bool = false

func _process(delta):
    print(b)
    b = !b

And I got this output:

False
True
False
True
False
...

randf() will get you a random sequence since the condition becomes true only if the generated random float is higher than 0.998

Hey, thx for trying! I have just run the same code in Windows and it also worked. The problem only occurs in Manjaro Linux. Can that make a difference?

There is no problem. What's happening is completely in accordance with your code.

I now ran the exact same code as you did:

var b: bool = false

func _process(delta):
    print(b)
    b = !b

However, the output was
False
False
True
True
False
False
True
True
...

I did the same thing on a different PC and got:
False
True
False
True
...

as expected. I have no clue what's going on.

The lines

b = not b

and

print(b)

in the original code are both in the same if block, therefore it should not be possible to change the value of b without printing it directly afterwards.

Hello @htilo,

I am running Godot 3.2.3 on archlinux, and I don't experience the randomness you have. The output is as expected:

True False True False ...

Are you still dealing with this issue? What is your Manjaro version?

Hi @glihm, I am still having the same issues. I am using Nibia 20.2.1.

Hello @htilo,

weird... are you running the 32 or 64 bit version of Godot?
The example you gave is the fully reproducible example right?

1 Answer

0 votes

I accidentally had the main scene in autoload. Deleting it from autoload solved the problem.

by (16 points)
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.