Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Suero152 opened this issue May 2, 2024 · 1 comment
Open

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

Suero152 opened this issue May 2, 2024 · 1 comment

Comments

@Suero152
Copy link

Suero152 commented May 2, 2024

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

@Suero152
Copy link
Author

Suero152 commented May 2, 2024

If someone read this, I solved it using another func inside .effect callable to do async things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant