i'm trying to make a rpg-style dialogue system in godot 4 by using tween.
here is my code:
var isrun = false
func addText(next_text):
isrun = true
maintext.text = next_text #maintext is label node
maintext.visible_ratio = 0
var tween2 = create_tween()
tween2.tween_property(maintext, "visible_ratio", 1, len(next_text) * readFast)
func _on_button_pressed():
if isrun == false:
addText("texttexttext")
elif isrun == true:
$addText.tween2.kill(self)
isrun = false
this is what i expected:
when i press button:
if it is the first time that i pressed the button: execute addText function
or if it is the second time that i pressed the button: kill tween2 in addtext funtion
excute addText function works well, but kill tween2 doesn't work
how can i solve this problem?
Judging from the example code you provided the problem is one of scope. You create the tween2
variable in the addText
function. Therefore it should be undefined/null in the _on_button_pressed
function.
Add a "global" (in your script) variable that holds the tween and try creating the tween in your _ready
function.