zero_secrets_unfound

  • 22 days ago
  • Joined Dec 10, 2024
  • 0 best answers
  • Okay, well, I have no idea what happened, but I messed around with some other stuff and it seems to be working now? As in, I don't have to save the first element of the DialogueLines array now. So that's not an issue anymore.

    I'm still open for suggestions on different ways of managing Dialogue, if anyone has any input! Is using .json files really worth it, or should I stick to Godot resources?

  • Hello! I've been coming up with a way to store the dialogue in my game. I have branching dialogues which are accompanied by character sprites. There is only one character the player can talk to at a time, so all I need is a way to store text + sprite for any dialogue line.

    I've come up with a solution involving resources:

    • SpriteResource stores a sprite name + sprite texture
    • DialogueLine contains a SpriteResource and a String of the dialogue
    • DialogueFull stores an array of DialogueLines, and a ChoiceResource (for branching dialogue)

    I've made a couple of DialogueFull resources, and filled the arrays inside with DialogueLines resources I created in the editor. However, on running the project I got an error because I was seemingly referencing a non-existent resource. I figured it was because I was using DialogueLines I'd created in the editor and had not saved as files, and so I saved the first DialogueLine in the array of the active DialogueFull. I thought I'd get an error for the rest of the DialogueLines that I have not saved, but the code run perfectly. I tried the same things with other DialogueFull resources, and got the same result.

    My questions are:

    • Why do I need to save the DialogueLine resource as a separate file in the first place? Can it not just save itself inside the array of the DialogueFull it's a part of?
    • Why is it only the first one I need to save? If the issue was that information cannot be pulled out of unsaved resources, why is it that the rest of them run just fine?
    • Is there a better way to implement the dialogue system? I know about plugins like Dialogue Manager, but I would prefer to build one on my own.
  • I'm building a collection of minigames in Godot, and I've run into a bit of a problem with the drag-and-drop mechanics. I've managed to implement this functionality into the game, however during testing I've discovered that when several objects are dragged one after the other very quickly, the previous object, which is not being currently dragged, may move with the one currently being dragged. I've tried to fix it by using call_deferred and such, but nothing seems to completely fix the issue.

    Any advice would be appreciated! Perhaps there is a better way to implement the click-and-drag functionality? The draggable objects on the screen may overlap, which is why I'm using buttons instead of area2D, but maybe I'm wrong in doing that?

    The Draggable hierarchy is:

    • Draggable (TextureButton)
    • - Area2D
    • - - CollisionShape2D

    The code for the draggable object:

    class_name Draggable extends TextureButton
    
    @export var drop_kind : String = ""
    
    var draggable : bool = false
    var is_inside_droppable : bool = false
    
    var body_ref = null
    var body_entered = null
    var body_exited = null
    
    var offset : Vector2
    var initial_position : Vector2
    var tween : Tween
    
    func _ready():
    	initial_position = global_position
    
    func _process(_delta):
    	if draggable:
    		if Input.is_action_just_pressed("click"):
    			initial_position = global_position
    			offset = get_global_mouse_position() - global_position
    			GlobalDragging.currently_dragging = true
    		
    		if Input.is_action_pressed("click"):
    			global_position = get_global_mouse_position() - offset
    			
    		elif Input.is_action_just_released("click"):
    			GlobalDragging.currently_dragging = false
    			
    			if !is_inside_droppable:
    				if tween:
    					tween.kill()
    				tween = get_tree().create_tween()
    				tween.tween_property(self, "global_position", initial_position, 0.2).set_ease(Tween.EASE_OUT)
    
    func _on_mouse_entered():
    	if !GlobalDragging.currently_dragging:
    		draggable = true
    		scale = Vector2(1.05, 1.05)
    
    
    func _on_mouse_exited():
    	if !GlobalDragging.currently_dragging:
    		draggable = false
    		scale = Vector2(1.00, 1.00)
    		
    func on_drop_area_entered(body : Area2D):
    	body_entered = body
    	
    	is_inside_droppable = true
    	body_ref = body
    	
    func on_drop_area_exited(body : Area2D):
    	body_exited = body
    	
    	is_inside_droppable = false

    The code for the drop area:

    class_name DropArea extends Area2D
    
    @export var drop_kind : String = ""
    
    func _ready():
    	area_exited.connect(on_area_exited)
    	area_entered.connect(on_area_entered)
    	
    	
    func on_area_entered(area : Area2D):
    	thumbs_up_emoji.call_deferred(area)
    	
    func on_area_exited(area : Area2D):
    	if drop_kind == area.get_parent().drop_kind:
    		area.get_parent().on_drop_area_exited(self)
    		
    func thumbs_up_emoji(area):
    	if drop_kind == area.get_parent().drop_kind:
    		area.get_parent().on_drop_area_entered(self)
    • Ok, I had a good night's sleep and figured it out by myself. The problem was the global position grabs the coordinates of the center of the sprite, which was the reason for the delay in the change of animation. All I had to do was apply a shift:

      var tile_data = tilemap.get_cell_tile_data(0, tilemap.local_to_map(Vector2(global_position.x, global_position.y + 18)))

      Now it works great. I'll leave this up in case someone runs into the same problem.

    • I'm new to working in Godot, and this is something I've been trying to figure out for a bit now. I searched for solutions, but couldn't find anything useful.

      To put it simply, I have ground type tiles and water type tiles. I want the character animation to change when the character is standing on water tiles.

      I've given the water tiles an "is_water" custom data layer, and then in the Player code, I check whether the player is standing on a water tile, and change the animation based on that. It does work, however there is a slight sprite changing delay when the character steps in and out of water (so the water animation still plays for a couple of frames when the player steps onto the ground, and the ground animation still plays for a bit when the player steps into the water).

      My question is whether is possible to somehow get rid of the delay, or maybe do this process in a different way?

      The relevant code:

      func _physics_process(delta):	
      	var forward_animation : String = "forward_run"
      	var back_animation : String = "back_run"
      	var right_animation : String = "right_run"
      	var left_animation : String = "left_run"
      	
      	var tilemap = get_tree().get_current_scene().get_node("TileMap")
      	var tile_data = tilemap.get_cell_tile_data(0, tilemap.local_to_map(global_position))
      	
      	if (tile_data.get_custom_data("is_water")):
      		forward_animation = "water_" + forward_animation
      		back_animation = "water_" + back_animation
      		right_animation = "water_" + right_animation
      		left_animation = "water_" + left_animation 
      		run_speed = water_run_speed