same code for differents variables?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Maranpis

Hello :slight_smile:

How can I use the same functions but depending on whether one variable or another uses them? For example:

onready var Dialogue_Loom =get_node("Npc/Dialogue_Loom")
onready var Dialogue_Guybrush =get_node("Player/Dialogue_Guybrush")

I want to use these two functions:

func _process(_delta):
	if dialogue.get_visible_characters()> dialogue.get_total_character_count():

func Timer_Timeout():

Any idea of how can I re-use these pieces of codes without having to write it twice for each variable?


:bust_in_silhouette: Reply From: Inces

You need to design Your subroutines in a way they have a shared code, with different parts based on passed arguments. For example :

func process():
menagedialogue( currentspeaker):

func menagedialogue(currentspeaker):
currentspeaker.visible = true
rest of speakers.visible = false

And so on, it requires some desgin creativity :).

Check this tutorial out. It is horrnendously long, but just rewind to the resources and dialogue section. It will definetely elevate your Godots level :slight_smile:

Hello Inces, thanks for your reply :slight_smile:

I’m still trying to get the use of arguments ¿Which tutorial do you recommend me to watch?

Thanks a lot.

Maranpis | 2021-12-10 17:46

hahah, I forgot to link in the end :slight_smile:

Inces | 2021-12-11 18:25