Looks like you're not logged in

Login or Register to continue

Lesson Q&A

Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.

  • Extra code in Practice 1intent-mantisIn the practice 1 script, one of the instruction comments inside the advance function says # Don't forget to call the show_text function I believe this comment is left over because this script uses show_image instead of show_text 1 4 May. 17, 2024
  • Consequences of L6 challengeLtommasiniAs I have done the L6 challenge about changing the duration of the tween according to the lenght of the text, I also had to do some adjustments regarding it: ```gdscript func show_text() -> void: var curr_item := dialogue_items[curr_item_index] rich_text_label.text = curr_item["text"] expression.texture = curr_item["expression"] rich_text_label.visible_ratio = 0.0 var tween = create_tween() #var text_duration := 1.5 var text_duration :float = curr_item["text"].length()/8.0 tween.tween_property(rich_text_label, "visible_ratio", 1.0, text_duration) var sound_max_length := audio_stream_player.stream.get_length() - text_duration var sound_start_pos := randf() * sound_max_length audio_stream_player.play(sound_start_pos) tween.finished.connect(audio_stream_player.stop) ``` In line 8 I had to declare the "text duration" var as a float otherwise it wouldn't work, but I don't really understand why. The error I get is: "Cannot infer the type of "text_duration" variable because the value doesn't have a set type." It also affects lines 10 and 11, same error. Not sure if the solution I have here is the best one, but it's working fine. Thanks! I'm really enjoying the course progression 3 4 May. 14, 2024
  • Error : Invalid get index 'regular' (on base: 'Dictionary').pikminfan71**Would love some help, Thanks in advance!** extends Control @onready var next_button: Button = %NextButton @onready var back_button: Button = %BackButton @onready var rich_text_label: RichTextLabel = %RichTextLabel @onready var audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer @onready var body: TextureRect = %Body @onready var expression: TextureRect = %Expression var current_item_index := 0 var dialogue_items: Array[Dictionary] = [ { "expression" : expressions["regular"], "text" : "I love burgers" }, { "expression" : expressions["happy"], "text" : "But with no cheese" }, { "expression" : expressions["regular"], "text" : "Because when I Hear a cow" }, { "expression" : expressions["sad"], "text" : "I cringe" }, ] var expressions := { "happy" : preload("res://assets/emotion_happy.png"), "sad" : preload("res://assets/emotion_sad.png"), "regular" : preload("res://assets/emotion_regular.png"), } func _ready() -> void: show_text() next_button.pressed.connect(advance_text) back_button.pressed.connect(rewind_text) func show_text() -> void: var current_item := dialogue_items[current_item_index] rich_text_label.text = current_item["text"] expression.texture = current_item["expression"] rich_text_label.visible_ratio = 0.0 var tween : Tween = create_tween() var text_appearing_duration: float = 1.0 tween.tween_property(rich_text_label, "visible_ratio", 1.0, text_appearing_duration) var sound_max_length := audio_stream_player.stream.get_length() - text_appearing_duration var start_sound_position := sound_max_length * randf() audio_stream_player.play(start_sound_position) tween.finished.connect(audio_stream_player.stop) func advance_text() -> void: current_item_index += 1 if current_item_index == dialogue_items.size(): current_item_index = 0 show_text() func rewind_text() -> void: current_item_index -= 1 if current_item_index < 0: current_item_index = dialogue_items.size() - 1 show_text() 4 3 May. 26, 2024
  • About Practice L10.P2AJ StudiosI was able to get it right except on the `show_party_member()` function I got an error stating: *Value of type "Dictionary" cannot be assigned to a variable of type "String".* I missed hint #4 where it says: each item has 2 properties, portrait and name. I was confused since in the previous practice: L10.P1 we accessed the textures by: `texture_rect.texture = items[item_index]`. Then I realized that L10.P1 Array is of type Texture, and L10.P2 Array is of type Dictionary. I have to admit, this one really got me. Nonetheless I just learned something new. 1 2 May. 23, 2024
  • Error: Function "length()" not found in base Dictionary.Nikita MyshkinThere was a task in the previous lessons. So that the duration of text input should be depending on its volume. Here is an excerpt of the code: `var text_appearing_duration := current_item.length() / 30.0` Now that we've added the array of dictionaries, it throws this error: *Parser Error: Function "length()" not found in base Dictionary.* I have already tried to fix: `var text_appearing_duration := current_item["text"].length() / 30.0` but it still doesn't work. Apparently the syntax is incorrect. Please tell me how to fix it. Here is the whole code: ```gdscript extends Control @onready var rich_text_label: RichTextLabel = %RichTextLabel @onready var next_button: Button = %NextButton @onready var previous_button: Button = %PreviousButton @onready var audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer @onready var body: TextureRect = %Body @onready var expression: TextureRect = %Expression var expressions := { "happy": preload("res://assets/emotion_happy.png"), "regular": preload("res://assets/emotion_regular.png"), "sad": preload("res://assets/emotion_sad.png"), "angry": preload("res://assets/extras/emotion_angry.png") } var dialogue_items : Array[Dictionary] = [ { "expression": expressions["regular"], "text": "I'm learning about Array..." }, { "expression": expressions["sad"], "text": "... and it is a little bit complicated." }, { "expression": expressions["happy"], "text": "I'm happy!" }, { "expression": expressions["angry"], "text": "Шел бы ты нахуй мудила и забери собой свои две сосиски!" }, ] var current_item_index := 0 func _ready() -> void: show_text() next_button.pressed.connect(advance) previous_button.pressed.connect(previous) previous_button.visible = false func show_text() -> void: var current_item := dialogue_items[current_item_index] rich_text_label.visible_ratio = 0.0 rich_text_label.text = current_item["text"] expression.texture = current_item["expression"] next_button.visible = current_item_index < dialogue_items.size() - 1 previous_button.visible = current_item_index > 0 var tween := create_tween() var text_appearing_duration := current_item.length() / 30.0 tween.tween_property(rich_text_label, "visible_ratio", 1.0, text_appearing_duration) var sound_max_lenght := audio_stream_player.stream.get_length() - text_appearing_duration var sound_start_position := randf() * sound_max_lenght audio_stream_player.play(sound_start_position) tween.finished.connect(audio_stream_player.stop) func advance() -> void: current_item_index = min(current_item_index + 1, dialogue_items.size() - 1) show_text() func previous() -> void: current_item_index = max(current_item_index - 1, 0) show_text() ``` 3 1 Jun. 30, 2024
  • Accessing Data in DictionaryStevenIs there an advantage to using: rich_text_label.text = current_item["text"] over rich_text_label.text = current_item.text? 1 1 May. 25, 2024
  • Accessing nested dictionary value directlyPaulIn the lesson, when dealing with Dictionaries within Arrays, we were storing the whole Dictionary in a variable, then using the variable with the name of the key to access the value. I was curious to see if you could go two layers deep in one go to access a value directly, which you can! So in case anyone else was curious and didn't work out the syntax, this was what I found: ```gdscript #To print a value stored in the key "text", which is in the first dictionary within the array. print(array_name[0]["text"]) ``` I can totally see the value in using the variable in this case by the way, so we can read any key in that dictionary quickly in different places, but good to know you can get in there directly as well! 1 0 Sep. 25, 2024
  • L10.P2 not passing "advance() does not trigger show_party_memberCerealThis is my code: extends ColorRect @onready var texture_rect: TextureRect = %TextureRect @onready var rich_text_label: RichTextLabel = %RichTextLabel @onready var button_next: Button = %ButtonNext @onready var button_previous: Button = %ButtonPrevious var items: Array[Dictionary] = [ { "name": "Dani", "portrait": preload("./assets/character_dani.png") }, { "name": "Gobot", "portrait": preload("./assets/character_gdbot.png") }, { "name": "Nova", "portrait": preload("./assets/character_nova.png") }, ] var item_index := 0 func _ready() -> void: button_next.pressed.connect(advance) button_previous.pressed.connect(rewind) show_party_member() # displays the party member's portrait and its name func show_party_member() -> void: rich_text_label.text = items[item_index]["name"] texture_rect.texture = items[item_index]["portrait"] # Increments the index each time is called. func advance() -> void: item_index += 1 if item_index >= items.size(): item_index = 0 else: show_party_member() # Decrements the index each time is called. func rewind() -> void: item_index -= 1 if item_index < 0: item_index = items.size() - 1 else: show_party_member() 3 0 Sep. 19, 2024
  • about autocomplete in the editormrelectronHi team, my background is mostly in strongly typed languages so autocomplete is always working great. however i am noticing that autocomplete in the godot editor is a bit lackluster, i get that this is due to the nature of GDScript being a dynamically typed language. but i noticed that if i give concrete types then it works better. so for the array of dictionaries i tried to use an enum as keys for the expression and text in hopes of being able to access them without typing a string for the key later on, but when i get to the show_text function, it seems like the editor forgot about the enum and doesn't give me hints. ```gdscript extends Control @onready var rich_text_label: RichTextLabel = %RichTextLabel @onready var next_button: Button = %NextButton @onready var back_button: Button = %BackButton @onready var quit_button: Button = %QuitButton @onready var audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer @onready var body: TextureRect = %Body @onready var expression: TextureRect = %Expression var expressions := { "happy": preload("res://assets/emotion_happy.png"), "regular": preload("res://assets/emotion_regular.png"), "sad": preload("res://assets/emotion_sad.png"), "angry": preload("res://assets/extras/emotion_angry.png") } enum {expressionKey,textKey} var dialogue_items:Array[Dictionary]= [ { expressionKey:expressions["regular"], textKey:"Roses are red" }, { expressionKey:expressions["happy"], textKey:"Violets are blue", }, { expressionKey:expressions["angry"], textKey:"I'm learning about Arrays", }, { expressionKey:expressions["happy"], textKey:"And so are you!", } ] func _ready() -> void: show_text() next_button.pressed.connect(advance_text) back_button.pressed.connect(back_text) quit_button.pressed.connect(quit_game) var current_item_index :int=0 func show_text()-> void: var current_item :Dictionary= dialogue_items[current_item_index] var text:String=current_item[textKey] var current_expression:Resource=current_item[expressionKey] rich_text_label.text = text rich_text_label.visible_ratio=0.0 var tween:Tween = create_tween() var text_appearing_duration :float=text.length()*0.08 tween.tween_property(rich_text_label,"visible_ratio",1.0,text_appearing_duration) expression.texture=current_expression var sound_max_lentgh := audio_stream_player.stream.get_length()-text_appearing_duration var sound_start_position := randf()*sound_max_lentgh audio_stream_player.play(sound_start_position) tween.finished.connect(audio_stream_player.stop) func advance_text()-> void: if(current_item_index<dialogue_items.size()-1): current_item_index+=1 else: current_item_index=0 show_text() func back_text()->void: if(current_item_index>0): current_item_index-=1 else: current_item_index=dialogue_items.size()-1 show_text() func quit_game()->void: get_tree().quit() ``` Here is my code, am i doing something wrong? 1 0 Aug. 30, 2024
  • Can´t complete L10P1untimely-dogfishI tried that practice, but it ends in an error in the test.gd file. I packed the issue here: [https://we.tl/t-JLVCxQmLHO](https://we.tl/t-JLVCxQmLHO) Can you have a look at it? 3 0 Aug. 17, 2024
  • Error invalid get index 'happy' (on base: 'Nil')NinjoshTrying to work out this error but having issues figuring it out. Any help would be great. Here is my code: ```gdscript extends Control @onready var next_button: Button = %NextButton @onready var rich_text_label: RichTextLabel = %RichTextLabel @onready var previous_button: Button = $PreviousButton @onready var audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer @onready var body: TextureRect = %Body @onready var expression: TextureRect = %Expression var current_item_index: = 0 var expressions := { "happy":preload("res://assets/emotion_happy.png"), "regular": preload("res://assets/emotion_regular.png"), "sad": preload("res://assets/emotion_sad.png") } var dialogue_items : Array[Dictionary]= [ { "expression": expressions["regular"], "text": "This is the first time I have programmed dialogue" }, { "expression": expressions["happy"], "text": "I have seen it so many times, interesting that I can now do it" }, { "expression": expressions["sad"], "text": "Well with help, but sooner or later if I keep practising I will get better" }, { "expression": expression["happy"], "text": "Besides having support is a good thing" }, ] func show_text(): rich_text_label.visible = true var current_item:= dialogue_items[current_item_index] var visible_ratio := rich_text_label.visible_ratio rich_text_label.visible_ratio = 0.0 rich_text_label.text = current_item["text"] expression.texture = current_item["expression"] var tween = create_tween() var text_appearing_duration :float = 5.0 var sound_max_length := audio_stream_player.stream.get_length() - text_appearing_duration var sound_start_position := randf() * sound_max_length audio_stream_player.play(sound_start_position) tween.tween_property(rich_text_label,"visible_ratio",1, text_appearing_duration) tween.finished.connect(audio_stream_player.stop) func advance(): current_item_index = current_item_index +1 if current_item_index == dialogue_items.size(): current_item_index = 0 show_text() else: show_text() func rewind(): current_item_index = current_item_index -1 if current_item_index < 0: current_item_index = 0 show_text() else: show_text() func _ready(): rich_text_label.visible = false current_item_index = -1 next_button.pressed.connect(advance) previous_button.pressed.connect(rewind) ``` 2 0 Jun. 16, 2024
Site is in BETA!found a bug?