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.

  • No autocomplete on event.button_index ?ThomoI'm a bit confused as to why Godot sometimes does not suggest any code. For example, when checking for a left click on the chest, nothing is suggested after writing `event.`, which would definitely throw me off and make me think I'm trying to write something that does not exist if I was on my own. Even writing `event.button_` does not make any autocomplete hint pop up. I've had this happen when setting the shader outline parameter, where it would not autocomplete `canvas_group.material.` with `set_shader_parameter()`, which I fixed by switching the code a bit and manually telling godot that the material was a ShaderMaterial like this: ```gdscript @onready var canvas_group: CanvasGroup = $CanvasGroup @onready var canvas_material: ShaderMaterial = canvas_group.material ``` And then using `canvas_material.set_shader_parameter("line_thickness", new_thickness)` Would there be a way to "fix" the autocomplete in the case of event.button_index ? 2 6 Apr. 08, 2024
  • Extra challenge: close the chest after opening itmatteoscopelAs a personal challenge, I wanted to make it so that I can close again the chest after opening it. I wanted to do it without using any variable, like we did in this chapter. I've written the following function. It works! Do you think there would be a cleaner way of doing this? ```gdscript func open() -> void: if animation_player.assigned_animation == "open": animation_player.play_backwards("open") animation_player.queue("RESET") else: animation_player.play("open") ``` 2 4 Jul. 05, 2024
  • L5.P2 problem.RossBCIf you actually use event.is_released() instead of event.is_pressed(), you fail the practice. The way it's worded, we are supposed to be checking on button release to clear the queue. The only time it succeeds is when the only code you change/add is queue.free() and leave event.is_pressed() as it is. 10 4 Apr. 08, 2024
  • is there a typesafe way to access/play animations without using strings?inferior-gnatSeems a bit brittle to use the string "open" to play the animation. As mentioned in the lesson, changing the animation name in the panel would break everything. 2 1 Jun. 01, 2024
  • Is this a better way to write the code considering readibility and autocomplete?Lucas PscheidtAbout the code where you talked about the _input_event() function: func _input_event(viewport: Node, event: InputEvent, shape_index: int): var event_is_mouse_click: bool = ( event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() ) if event_is_mouse_click: pass I personally found it a little bit confusing and hard to use this function in this way because it does not give us the autocomplete suggestion for the "button_index". It would require a lot of practice and use of this function to know and remember to write this, in my opinion. For teaching purpose, wouldn't be better to write the code in a way which could suggest the autocomplete for that object? Like in this way that I came up with (it also uses one less line of code and I found personally better to read): func _input_event(viewport: Node, event: InputEvent, shape_index: int): if event is InputEventMouseButton: var event_left_mouse_click: bool = event.button_index == MOUSE_BUTTON_LEFT var event_is_pressed = event.is_pressed() if event_left_mouse_click and event_is_pressed: pass Just a suggestion to make it easier for beginners to understand, but I don't know if everything is fine with it, so please correct me if I am wrong. 5 1 May. 31, 2024
  • is or == ?SebI was curious, I tried : `event == InputEventMouseButton` and nothing happened. So, yes, "is" is different from == ;) The lecture says it "checks if a value is of a specific type", which I found hard to understand. I read the documentation of "InputEventMouseButton", it's a class. So if I understand correctly, "is" checks that "event" is of the class "InputEventMouseButton" whatever the values of its different properties are. Is that correct? I also tried to read [https://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is](https://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is) which both helped and lost me XD. Anyway, I was happy like a child when the chest did animate on click. :) 1 1 Apr. 16, 2024
  • event_is_mouse_click: first check needed?HollowIs it necessary to check if the event is of type InputEventMouseButton if we have the second check which already determines if it is the left mouse button? 8 1 Apr. 08, 2024
  • What is the difference of _input_event(), _input() and _unhandled_input()?SebabeI'm just wondering what the main difference is between these methods and when to use which one? 1 1 Apr. 01, 2024
  • Difference between get_viewport() and viewport in _input_eventold-fashioned-mouseHello, quick question. I was wondering what the difference between what `get_viewport()`returns and the `_input_event` viewport parameter was (if there is one)? As far as I understand `get_viewport` returns the nodes current viewport anyway (in the case of multiple windows)? Thanks! 1 1 Mar. 23, 2024
  • Thinking about accessibility and control remappingPaul```gdscript func _input_event(viewport: Viewport, event: InputEvent, shape_index: int): var event_is_mouse_click: bool = ( event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() ``` Not that I have any idea about putting front-end remapping in place at this stage, but with that, and accessible design in mind, is this sort of code flexible? It reads to me that it's 'hard-coded' to expect a left mouse click and nothing else. Would you require a different approach if you knew you intended to support multiple input methods or editable controls in your game? 1 0 Sep. 14, 2024
  • Same result using a signal, not sure which approach is betternervous-woodpeckerI saw we have access to the `input_event` signal on the parent object type `CollisionObject2D` so my instinct was to use that approach right away. That worked and is way less code. `input_event.connect(_on_input_event)` `...` `func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:` ` if event.is_action_pressed("left_click"):` ` animation_player.play("open")` What's difference? Thanks! 3 0 Sep. 12, 2024
  • is_open variable and best practicesdweipertI wouldn't say using a `is_open` variable is not best practice. Certainly depends on the use-case. If you'd like to check from the outside whether a chest was opened or not your definetely need a variable to keep track of that. Or a function `is_open()` that you can call that then checks whether `input_pickable` is `true` or `false`. Using `is_open` does feel more like a state check to me and then I wouldn't expect to have to call a function and instead check the property. So the variable does feel to me like best practice. I say this with 15 years programming experience, albeit full-stack web languages. I'm only now starting to get into game dev with the actual intent to maybe build a complete game. So maybe the experiences built in the game dev field produce different expectations and best practices when actually completing a game start to finish. Looking forward to hear your thoughts :) 3 0 Sep. 12, 2024
  • Alternative way to prevent chest from opening again (Not a question) Abdul Hannan AhmedHi! I found an alternate way to prevent the chest from opening again. I just wanted to ask if that solution was viable or not? ```gdscript func open() -> void: animation_player.play("open") $CollisionShape2D.disabled = true ``` Thanks in advance! 1 0 Sep. 03, 2024
  • L5.P1 AnimationPlayer Nodebig-hearted-emuL5.P1's door_open.tscn has an AnimationPlayer Node that only has a "rotation" track that is 0.001 seconds long. (0.5.1 win) When doing the practice, on the first attempt I only read the MISSION without opening the instructions and go from there. When I checked the AnimationPlayer for the name of the animation track and saw "rotation" I thought that was it. I imagined we'd have to do the animation ourselves. It fails the test. The practice completes correctly when playing the "open" animation, but the track is not in the AnimationPlayer Node. I'm a bit confused as to what "open" animation is playing then? 4 0 Aug. 05, 2024
  • Is there a way to keep "Chest" instances from overlapping incorrectly?Turned_Into_A_FrogI noticed that if I have 3 chests; their tree order is (Chest, Chest2, Chest3) and their placement from background to foreground is (Chest3, Chest2, Chest). So when I activate the animation they overlap in a weird way due to draw order, Is there a way to make the overlap based on position? or is this more of a level design and tree organization issue? 1 0 Aug. 02, 2024
  • is_released vs is_action_releasedIronEvaHey, I made a mistake and used the is_action_released by accident, but I was curious as to what the differences are as they both came up in the auto-completion popup. I tried looking online and couldn't find anything about the difference between the two. Bit of a guess here, but is it to do with input mapping? P.S One thing I know is this, I am terrible at looking up what things do in Godot. 2 0 Jul. 16, 2024
  • Are these two the same?miniature-gazelleif event_is_mouse_click: if event_is_mouse_click == true: Are these two the same? if yes, shouldn't we use it like that cause it makes it a lot more clear what it does, at least for a newbie like me :D 2 0 Jul. 14, 2024
  • Question about _functionHazlarHello, The input_event function is a function that is neither called in a context like func _process() or ready() , so is it a "passive" function like ready() or "active" like _process(). Because ready is called once, and process() is triggered continuously but here it is between the two, and I do not think that this state exists right? Just for the correction the shape_index parameter is named on my side by the godot autocompletion as shape_idx . Thanks ! 3 0 Jul. 10, 2024
  • A few questions about the Viewport parameter and operators.Nikita Myshkin```gdscript func _input_event(viewport: Viewport, event: InputEvent, shape_idx: int) -> void: ``` 1.I set the `Viewport` parameter for the Node location and the work has not changed in any way. Do I understand correctly that the Viewport covers the entire area of the window, and the `Node` covers only the `Node` node? Then which one is better to use? 2.If I change `is` to `==` then the chest stops opening. What is the fundamental difference? After all, as I understand it, `is` and `==` are the same thing. 3 0 Jun. 26, 2024
  • How to Make Multiple AnimationPlayers Play Animations Independently in Godot Using C#?jadecui666I tried to recreate a tutorial's animation functionality using C#. I created a chest scene with an `open` animation in the AnimationPlayer. Then, I placed multiple instances of this chest scene in the main scene. However, when I click on a single chest, all the `open` animations play simultaneously. It's worth noting that when I write the same logic using GDScript, this issue does not occur. Each chest instance's animation plays independently. Does this mean there are differences in how C# and GDScript handle AnimationPlayer? ```gdscript using Godot; using System; namespace GdquestCsharp.chest_level { public partial class Chest : Area2D { CanvasGroup _canvasGroup; AnimationPlayer _animationPlayer; // Called when the node enters the scene tree for the first time. public override void _Ready() { _canvasGroup = GetNode<CanvasGroup>("CanvasGroup"); _animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer"); SetOutlineThickness(3); this.MouseEntered += OnMouseEntered; this.MouseExited += OnMouseExited; } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { } public override void _Input(InputEvent @event) { base._Input(@event); if (@event is InputEventMouseButton mouseButton && mouseButton.Pressed && mouseButton.ButtonIndex == MouseButton.Left && InputPickable) { Open(); } } private void OnMouseEntered() { var tween = CreateTween(); tween.TweenMethod(Callable.From<float>(SetOutlineThickness), 3.0f, 6.0f, 0.08f); } private void OnMouseExited() { var tween = CreateTween(); tween.TweenMethod(Callable.From<float>(SetOutlineThickness), 6.0f, 3.0f, 0.08f); } private void SetOutlineThickness(float thickness) { _canvasGroup.Material.Set("shader_parameter/line_thickness", thickness); } private void Open() { _animationPlayer.Play("open"); InputPickable = false; } } } ``` 2 0 Jun. 19, 2024
  • Click starting outside the balloon but releasing inside it still works.GrahamIn the instructions for L5.P2, you say this: > This is useful for cases like pressing confirmation buttons: you generally don't want to confirm an action if the player clicks and drags the mouse outside the button area before releasing it. This made me think to try - what if i clicked and dragged the mouse from outside the balloon into the balloon then released it, what would stop it from popping? The answer of course is, *nothing*. My default logic would be to check when the mouse enters the Area2D if the mouse button left is already being pressed, and if so, don't do anything else. Would that be the best way to go about that? 3 0 May. 01, 2024
  • Exercise 2 - Cannot call method 'queue_free' on a null valueNekrysWhen I tested this on the BallonPop node alone, it works like a charm, the balloon only 'pops' when I release the button. Issue is that when I run the code on the main scene (PopTheBalloon) it gives me the title error! here is a copy of the code: ```gdscript extends Area2D @onready var canvas_group: CanvasGroup = $CanvasGroup func _input_event(viewport: Node, event: InputEvent, shape_index: int): var event_is_mouse_release: bool = ( event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_released() ) if event_is_mouse_release: canvas_group.queue_free() ``` 3 0 Apr. 27, 2024
  • _input_event() on own projectsHermundureAs an example, if I would like in an Old-School-RPG (like Dungeon Master) want to open the inventory of a character after klicking on his portrait in the main screen, would I use _input_event() for such a task or is the lesson about _input_event() more of a middle point to learning another concept of achieving likeminded tasks? 2 0 Apr. 19, 2024
  • Why no mouse_click event?AlainThere is a `mouse_entered` and a `mouse_exited`, is there a specific reason why there is no `mouse_click` event? It would be a nice shortcut to the conditional checking code that we have to put in `input_event`` 1 0 Apr. 17, 2024
  • Why use AnimationPlayer = $AnimationPlayerkooky-seahorseJust checking if there's a reason we use *animation_player: AnimationPlayer = $AnimationPlayer* because when dragging animation player from the scene tree it inputs as *animation_player: $AnimationPlayer* - this is also consistent with the previous @onready we made for the canvas_group so wasn't sure if it was a best practice thing or if its needed to make the code work. 1 0 Apr. 11, 2024
  • Ballon Pop PracticeAJ StudiosI was able to pass the practice however the ballon won't disappear when I click on it. I checked the practice solution and the script is the same as mine. So the green checkmarks are present but the ballon node won't be freed. 7 0 Apr. 04, 2024
  • Combining boolean expressions in variablesRaspiI wonder, when executing and assigning a var an expression like that, when you call the variable, when is this evaluated? Only during the variable assignment or every time is called? ```javascript var event_is_mouse_click: bool = ( event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() ) ``` I imagine the result in assigned and not re-evaluated in every check, right? If I want to re-evaluate that I'd have to move thins into a method. Is that right? 1 0 Apr. 01, 2024
  • Possible typo?MartinBCould just be me, sometimes I have trouble reading things but there's a part just after adding the input event function. It says this: *Godot call the `_input_event()` function whenever:* Is it 'Godot **calls...'** instead? 1 0 Mar. 30, 2024
  • Can't use current_animation == "open" to prevent chest animationGurkI tried using the current animation property to test if the animation does not play when clicked, but it did play again. It seems the current_animation property only gets the "open" value during the playing duration, before and after it will stay with an empty string. It seems that this condition will not prevent the chest from opening again, but prevent the open animation during its play. Reading the documentation it seems there is another possibility, I had to use the property "assigned_animation" that gets the last played animation. ```gdscript func open() : if(animation_player.assigned_animation != "open"): animation_player.play("open") ``` 3 0 Mar. 23, 2024
Site is in BETA!found a bug?