#changing values in autoload script crashes the game
1 messages · Page 1 of 1 (latest)
Autoloaded scripts are loaded into the scene tree next to root whether they are attached to a Node or not
well yeah at first it was just a script but since it kept crashing i tought attaching it to a node could change something, it did not
and just tried changing from a Dictionnary from simple vars but it also crashes the game when trying to change the values
i have another scene with a script attached to a 3dnode
it's supposed to change the value when i click on a cube
mouse_in = true
print("quoi")
body.set_material_override(ShaderOn)
while mouse_in == true:
if Input.is_action_just_pressed("Left_click"):
Stats.money +=1 ```
Ah, a wild while loop appears
can you replace Stats.money += 1 by a simple print statement to make sure it's not the while loop that is crashing the game ?
I think that you can try and use an if loop instead if it's the culprit
actually, seems like it crashes when my mouse enters one of the cube, so it's not even the fact of clicking on it i think
I think that it makes sense because whenever your mouse enters the Area and the signal is triggered the while loop is set off 
onready var body = $Area/Mesh/Shader
onready var ShaderOn = preload("res://Terrain/Materials/CubeHover.tres")
onready var ShaderOff = preload("res://Terrain/Materials/CubeDefault.tres")
var mouse_in = false
func _ready():
body.set_material_override(ShaderOff)
pass # Replace with function body.
func _on_Area_mouse_entered():
mouse_in = true
print("quoi")
body.set_material_override(ShaderOn)
while mouse_in == true:
if Input.is_action_just_pressed("Left_click"):
# Stats.money +=1
print("abc")
func _on_Area_mouse_exited():
mouse_in = false
print("feur")
body.set_material_override(ShaderOff)
, here is the full script
ye but i don't even have the time to click on it before it freezes
omg you were right
seems like replacing the while with an if solved the crash
it loops as long as the mouse_in statement is true, and it is always true when the mouse enters the area
Nice !
tough it's doesn't print when i click on it💀
is Left_click properly defined as an action in the project settings ?
seems like it
I know what the problem is, this signal is only triggered once, the moment the mouse enters the Area, so it only checks for the action once in that instant
oh yeah that makes sense
then how could i detect an input while the mouse is in the cube without creating an infinite loop again?
you can move that block of code in a function that loops continously like _process
this block : ```
if mouse_in == true:
if Input.is_action_just_pressed("Left_click"):
Stats.money +=1
print("abc")```
yay !
