Changing a variable in _process does not always work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By htilo
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”.

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

bloodsign | 2021-03-02 06:49

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?

htilo | 2021-03-02 11:54

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

Szesan | 2021-03-02 13:35

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.

htilo | 2021-03-02 17:28

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.

htilo | 2021-03-02 17:38

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:

False
True
False
...

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

glihm | 2021-03-03 16:14

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

htilo | 2021-03-03 16:33

Hello @htilo,

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

glihm | 2021-03-03 19:30

:bust_in_silhouette: Reply From: htilo

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