我们正在创建不太混乱的LonnyLips脚本。然后, 首先, 创建一个StoryBook节点, 然后将每个故事作为StoryBook的单独子节点, 并使每个故事使用相同的脚本, 我们希望新脚本为每个故事保存数据。
然后我们创建一个节点。单击加号(+)添加节点。

文章图片
在这里, 我们可以在下面看到该节点已创建。

文章图片
节点的属性。

文章图片
然后将” 节点” 名称重命名为StoryBook。

文章图片
之后, 创建一个名为story0的节点, 该节点是StoryBook的子级。然后创建其名为Story0的子节点。

文章图片
右键单击节点Story0, 然后单击附加的脚本以打开文本。

文章图片
然后从路径中删除0后创建它。

文章图片
这是脚本选项卡。

文章图片
编码:

文章图片
再创建一个名为story1的节点, 它是story0的副本。
要制作任何节点的重复节点, 请右键单击该节点, 然后转到重复或表达控制权以进行其下一个系列。或者, 我们可以单击关键字ctrl + D, 这是重复项的快捷方式。

文章图片
Story0中的代码:
extends Nodevar prompts=["a happy name", "a noun", "adverb", "adjective"]var story = "It takes many %s deeds to build a %s reputation, and %s bad one to %s it."
复制节点1之后, 然后在代码中添加导出功能, 如下所示。

文章图片
在代码中添加导出函数后, 这将在属性中发生:

文章图片
我们也可以在检查器属性中添加一个故事。然后从如下所示的检查器属性中相应地更改其故事。

文章图片

文章图片
我们还可以添加数组和数组类型, 如下所示:

文章图片
但是现在, 我们不这样做:
如果要在脚本中添加一个数组, 我们将进行编码, 然后它将自动显示在我们的属性中。

文章图片
在这里, 我们使用键入的G.DScript。
我们可以看到同时按下ctrl的任何关键字的描述和特定关键字。

文章图片
代码如下:

文章图片
或者我们可以用字符串代替” 。”

文章图片
然后, 我们将访问lonnylips.gd并将所有故事注释到脚本中, 如下所示。

文章图片
lonnylips.gd的示例:
extends Controlvar player_words=[]#var template = [#{# "prompts":["a name", "a noun", "adverb", "adjective"], #"story" : "It takes many %s deeds to build a %s reputation, and %s bad one to %s it."#}, #{ # "story":"There once was %s called %s who searched far and wide for the mythical %s noun of %s.", # "prompts": ["a noun", "a name", "an adjective", "another name"], #}, #{ # "story":"Once upon a time a %s ate a %s felt very %s. It was a %s day for all good %s.", # "prompts": ["a name", "a thing", "a feeling", "another feeling", "some things"], #}, #{ # "story":"There once was %s called %s that lived as %s as a %s." , # "prompts": ["a thing", "a name", "a descrition", "a thing"], #}, #{ # "story":"There once was %s called %s who searched far and wide for the mythical %s noun of %s.", # "prompts": ["a noun", "a name", "an adjective", "another name"], #}, #{ # "story":"a Poem.\n\n1 I was a %s as can be, \n then we could call me %s, \n and i would talk to %s ", # "prompts": ["a noun (a thing)", "an adjective(a description word)", "a person's name"], #}, #{ # "story":"Dear %s, I hope this letter finds we well. I have spent the past three weeks in %s researching the %s of donkies for my new book. I miss you hesitantly, and whenever i see a %s I think of u. ", # "prompts": ["a person's name", "the name of a place", "the plural of a noun", "another name"] #}, #{ # "story":"Once upon a time, a %s hero called %s was sent to %s, tio defeat a %s %s. He did so, return to defeat %s", # "prompts": ["an adjective", "a person's name", "a place", "an adjective", "a noun", "another place"], #}, #{ # "story":"The ultimate pizza recipe. \n\n Moix one packet of %s with three spoonfuls of flour. Knead it as it %s then put the %s and %s on it, after that open the oven and %s it.", # "prompts": ["a noun", "an adjective", "another noun", "yet another noun", "adjective"] #} #]var current_storyonready var PlayerText= $VBoxContainer/HBoxContainer/PlayerTextonready var DisplayText= $VBoxContainer/DisplayTextfunc _ready(): randomize()# current_story=template[randi()% template.size()] set_current_story() DisplayText.text="Welcome all of u in the world of game and have a wondeful time!" check_player_words_length() PlayerText.grab_focus()func set_current_story(): randomize() var stories = $StoryBook.get_child_count() # is used for how many children u have as here are 4 chilren 0, 1, 2, 3. var selected_story=randi()%stories current_story.prompts= $StoryBook.get_child(selected_story).prompts current_story.story= $StoryBook.get_child(selected_story).story# current_story=template[randi()% template.size()]func _on_PlayerText_text_entered(new_text): add_to_player_words()func _on_TextureButton_pressed(): if is_story_done():get_tree().reload_current_scene() else:add_to_player_words() func add_to_player_words(): player_words.append(PlayerText.text) DisplayText.text="" PlayerText.clear() check_player_words_length()func is_story_done(): return player_words.size() == current_story.prompts.size()func check_player_words_length(): if is_story_done():end_game() else:prompt_player()func tell_story(): DisplayText.text= current_story.story % player_wordsfunc prompt_player(): DisplayText.text += "May I have" +current_story.prompts[player_words.size()]+"please?"func end_game(): PlayerText.queue_free() $VBoxContainer/HBoxContainer/Label.text="Again!" tell_story()
之后, 我们将故事复制到story0(故事1)的属性中。
【故事书-故事对象(JSON)】故事0

文章图片
故事1

文章图片
我们可以添加更多类似以上的故事。
在这里, 我们还要创建两个以上Story2, story3之类的故事, 并在其中编写说明。

文章图片
在这里, 创建了四个故事。在这里也填写故事并排列。
更新代码以检查员形式编写故事时:
extends Controlvar player_words=[]var current_storyonready var PlayerText= $VBoxContainer/HBoxContainer/PlayerTextonready var DisplayText= $VBoxContainer/DisplayTextfunc _ready(): randomize() set_current_story() DisplayText.text="Welcome all of u in the world of game and have a wondeful time!" check_player_words_length() PlayerText.grab_focus()func set_current_story(): randomize() var stories = $StoryBook.get_child_count() # is used for how many children u have as here are 4 chilren 0, 1, 2, 3. var selected_story=randi()%stories current_story.prompts= $StoryBook.get_child(selected_story).prompts current_story.story= $StoryBook.get_child(selected_story).storyfunc _on_PlayerText_text_entered(new_text): add_to_player_words()func _on_TextureButton_pressed(): if is_story_done():get_tree().reload_current_scene() else:add_to_player_words() func add_to_player_words(): player_words.append(PlayerText.text) DisplayText.text="" PlayerText.clear() check_player_words_length()func is_story_done(): return player_words.size() == current_story.prompts.size()func check_player_words_length(): if is_story_done():end_game() else:prompt_player()func tell_story(): DisplayText.text= current_story.story % player_wordsfunc prompt_player(): DisplayText.text += "May I have" +current_story.prompts[player_words.size()]+"please?"func end_game(): PlayerText.queue_free() $VBoxContainer/HBoxContainer/Label.text="Again!" tell_story()
输出如下:

文章图片

文章图片

文章图片

文章图片

文章图片
在下一个教程中, 我们将通过JSON了解StoryBook。
推荐阅读
- GDscript中的工具模式
- 引用函数
- 电脑设置锁屏密码怎样设置?本文教您设置办法
- 驱动精灵万能网卡版,本文教您驱动精灵万能网卡版怎样运用
- 笔记本cpu温度高怎样办,本文教您笔记本电脑cpu温度高怎样办
- dat文件用啥软件打开,本文教您电脑中DAT分类的文件怎样查看
- 如何清理ie缓存,本文教您win7如何清理ie缓存
- 电脑亮度怎样调,本文教您电脑屏幕亮度调节办法
- 鼠标驱动,本文教您怎样更新鼠标驱动