Skip to content

R.effect won't work with async functions. #4

Description

Trying to call an async function without "await".

My code:

extends BoxContainer

signal change_tab(new_tab: String, )

var navbar_store = R.store({ # or R.state({ ... })
	"current_tab": "menu_home", # NOTE: This needs to be the button name.
	"hide_tabs": false
})
var debounce = false


# Called when the node enters the scene tree for the first time.
func _ready():
	$"../PlayerInfo/TextureProgressBar/PlayerName".text = NakamaConnection.session.username if NakamaConnection.session else 'USERNAME'
	R.effect(_on_tab_change)
	for node in get_children():
		# BUTTONS BLACKLIST
		if !node is Button: continue
		if node.name in ['TouchArena']: continue
		node.pressed.connect(func():
			if debounce: return;
			debounce = true
			navbar_store.current_tab = node.name
			await get_tree().create_timer(.3).timeout
			debounce = false
			)
	

func _on_touch_arena_pressed():
	SceneManager.switch_scene('touch_arena')

func _on_tab_change(_ignore):
	for node in get_children():
		if !node is Button: continue
		if node.name == navbar_store.current_tab:
			node.disabled = true
			continue
		node.disabled = false
		
	debounce = true
	
	var component = await SceneManager.swap_node(
		$"../../SectionContainer".get_child(0), 
		navbar_store.current_tab, 
		true
		)
		
	if component and component.instantiated_scene:
		var component_node: Node = component.instantiated_scene
		if component_node.has_user_signal('change_tab'):
			var change_tab_array: Array = component_node.get_signal_connection_list('change_tab')
			if len(change_tab_array)>0:
				component_node.disconnect('change_tab', change_tab_array[0].callable)
			component_node.connect('change_tab', func(tab_name, hide_tabs):
				print(tab_name, hide_tabs)
				)
			
	debounce = false

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions