I have a problem with an exported set of boolean variables, flags to enable an Area2D feature:
tool
extends Area2D
signal direction_changed
export(bool) var allow_right
export(bool) var allow_left
export(bool) var allow_up
export(bool) var allow_down
var controlled_component = null
var directions: PoolVector2Array
var direction: Vector2
func _init():
init_directions()
func init_directions():
print_debug(allow_down, allow_left, allow_right, allow_up)
directions = []
if(allow_right):
directions.append(Vector2(1,0))
if(allow_down):
directions.append(Vector2(0,1))
if(allow_left):
directions.append(Vector2(-1,0))
if(allow_up):
directions.append(Vector2(0,-1))
and this results in showing the flags in my Scene inspector:
what I don't get is why if I flag a couple of them like this:
why the print_debug
statement results in this:
FalseFalseFalseFalse
Shouldn't two of the bool variables be set to True
?
Am I missing something?
You are using a tool script, which runs inside the IDE. Therefore the "_init()" function (where you call "init_directions()" with print_debug) is called when you open a scene with this script for the first time. When you make a change in the inspector, the change will be applied if you save, close the scene and open it again.