我想要变量
first_playthrough
当false
场景重新加载时,它将不再显示文本“来自 Number Guesser 的你好”。但它仍然显示它。
因此,它要么是:它从未变成false
,要么它变成了false
,但后来又回到了true
。
代码的缩短版本:
extends Node
var first_playthrough = true
func _ready():
# this is here so it will show the message
first_playthrough_checker()
func first_playthrough_checker():
# problem here is that, the message below still shows even though i thought i set it to 'false' already.
if first_playthrough == true:
text_printer("Hello from Number Guesser!\n\n")
func _restart_game():
#I've tried everywhere else. Thought it would work here. i was wrong.
get_tree().reload_current_scene()
first_playthrough = false
一种解决方案是持久数据存储。但也许对于像这样一个简单的游戏,它不再需要了?我在这里做错了什么?
如果需要,我会发布整个脚本。