Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ArAdev | |
Old Version | Published before Godot 3 was released. |
Hi, I’m having problems importing variables from another scenes that are constantly changing.
The thing Im trying to program is an equip weapon menu. I’m using the Optionbutton node
in a scene, where I store a variable in int numbers (0,1,2,3…) that are the options to choose and when I change the option on the node it change the var number. Is something like this:
extends Node2D
export var select_weapon=0
func _on_Weapon_option_item_selected( ID ):
if ID==0:
select_weapon=1
if ID==1:
select_weapon=2
if ID==2:
select_weapon=3
if ID==3:
select_weapon=4
When I import the variable into the player scene, the variable doesn’t change, doesn’t matter how much times I try to change the option , it stays always as the default value(0).
Here is what I try to do in the player’s script:
extends Node2D
var menu = preload("res://Weapon_sel.tscn")
var menuins = menu.instance()
func _ready:
set_process(true)
func _process(delta):
var get_weapon= menuins.get("select_weapon")
print(get_weapon)
It doesn’t matter how much I try to change the option in the menu, the var in the player script always return a 0.