SparksTheGamer

  • Dec 8, 2023
  • Joined Aug 6, 2021
  • 0 best answers
  • Tomcat Strange. I can't drag them in the node tree, I even tried ticking "Drag to rearrange"... I can't right-click and choose "Move Up" either

    I'm guessing some other setting somewhere in this project is messing with it somehow...

    The console prints "Reparent Node" and "Move Node In Parent" when I drag or Move Up respectively but nothing changes.

    • Hello, I have a settings window with tabs breaking up the settings. I just added a controls tab, but it added it as the last tab and I want to move it to be the second tab. However godot won't let me drag and drop the node to change the order? Is there a way to change the order of the tabs?

      • Thanks for the discussion. In this case I'm reading a lot of key mappings and need it to be a blank string if there's no mapping so InputMap.action_get_events("ui_accept")[0].as_text()

        I'm currently thinking of storing the length of the action events and then using that for the boolean test.

        var actionCount = InputMap.action_get_events("ui_accept").size()
        UiAcceptButton1.text = InputMap.action_get_events("ui_accept")[0].as_text() if actionCount >= 1 else ""
        UiAcceptButton2.text = InputMap.action_get_events("ui_accept")[1].as_text() if actionCount >= 2 else ""
        UiAcceptButton3.text = InputMap.action_get_events("ui_accept")[2].as_text() if actionCount >= 3 else ""
        UiAcceptButton4.text = InputMap.action_get_events("ui_accept")[3].as_text() if actionCount >= 4 else ""

        • xyz replied to this.
        • In other languages you can do
          var foo = a[0] | b
          which sets foo to a[0] unless it evaluates as false (undefined, null, false etc), then it sets it to b.

          It looks like in godot you have to do
          var foo = a[0] if a[0] else b
          which is an unfortunate repeat of a[0] meaning you either have to define a[0] to a new variable first, or look it up twice...

          • Godot 4.1

            I have a series of richTextLabel nodes that appear inside a VBoxContainer, new ones appearing under existing ones.

            I'd really like the new label to smoothly slide the existing ones up, so that you can continue reading, but I can't work out how. Because it's part of a vbox container, I can't use an animation to smoothly change the size of the node, and if I animate the scale of the richTextLabel the animation plays, but the space the node takes up within the Container is that of its maximum, not-animated size. The animation isn't respected by the parent.

            Is there a way I can achieve this, or is there a different parent node than VBoxContainer that I could use to achieve this effect more neatly?

            Note: I'm already animating in the words but this isn't as smooth as I like. If i use visible characters then after every line, all the text snaps up which is a lot of small movements all the time, and if I use visible ratio, I get closer to the effect I want where the text only moves up once when a new paragraph appears, but it's still a very sharp motion that I'd love to smooth.

            Paragraphs in the scene (left) with the editor structure (right)

          • So I identified the issue which I'll post here in the unlikely event this happens to another person. My game has two font options, default and Open Dyslexic. The way the game changes fonts is by iterating over all nodes that can take a theme and giving them one or the other font theme. This was overwriting my custom button themes 😰

          • A good suggestion, I just tried it but it doesn't seem to have fixed the issue. I removed the theme from the individual buttons and the control node, saved, then re-added the theme to the control node and saved.

          • Hello! I have a weird issue where my custom tres theme for some buttons applies correctly in the 2D editor, but in the actual game the theme isn't visible. This happens even after restarting Godot.

            I tried googling the issue and couldn't find a solution that worked for me since most people seem to report the other way around - theme works in game but not in the editor.

            I have tried applying the theme to the root control node, the button itself, and both.

            Game (left) vs editor (right)

            Theme applied to root control node from a saved tres

            The theme has the same settings for all states of the button

            Kinda stumped and would appreciate suggestions, thanks!

          • xyz AWESOME! I strongly suspected it was some sort of "you need to tick a box" thing, I really appreciate the answer, this now worked correctly immediately and I have Learned A New Thingâ„¢

          • Megalomaniak The set parcel type function is called in a for loop, so it's run multiple times, and the other parts of the set function do correctly apply per parcel. The texture is correct, the texture offset is correct, and the parcels each report their correct volume value. ONLY the collision size experiences this weird syncing

          • Megalomaniak Oops! That was left over from debugging, but removing it doesn't fix the issue. I've updated the parcel code to remove the ready in the post above.

            If the last parcel added to the scene is a 3x1, ALL parcels will then have their size be 384,128, for example, so it's not that they are all just always 128,128

          • Hello! I'm very new to godot but not to programming. I have a weird thing happening and I can't work out the cause.

            My game has several instances of a parcel scene. When instantiated, the parcel is told what size of parcel it is. It sets its texture, collision box, texture offset and internal variables to make it behave correctly for that size.

            What's really odd is that each type of parcel works correctly when instantiated, but if I have multiple sizes of parcel in the scene at once, even though they all maintain their correct texture and variables, their collision sizes are all updated to the last shape that was added to the scene.

            I'm confused because I event print their collision size values to the output as they're added and it's correct, so I don't know when it gets changed, why, or why only that property is somehow synced between them but other properties remain unique.

            Main scene:

            Node 2D [script]

            • Control
              Main.gd
              extends Node2D
              
              var Parcel = preload("res://objects/parcel.tscn")
              @onready var grid = $Control/GridContainer
              var parcels = {"1x1":5, "2x1": 3,  "3x1":1, "2x2":2}  #an example output from generate_puzzle()
              
              # Called when the node enters the scene tree for the first time.
              func _ready():
              	generate_puzzle() #this fills the parcels variable and doesn't touch any nodes
              	for type in parcels:
              		for parcel in parcels[type]:
              			var box = Parcel.instantiate()
              			box.parcel_dropped.connect(dropped_parcel)
              			print("added box type " + type)
              			box.set_parcel_type(type)
              			box.start_position = Vector2(80+(130*round(parcel/7)),100 + 130*(parcel%7))
              			add_child(box)

            parcel scene:
            Node2D [script]

            • Texture (Sprite2D)
            • Area2D
              --CollisionShape2D
            parcel.gd
            extends Node2D
            
            var texture_1x1 = preload("res://Assets/Art/Objects/Parcels/1x1.png")
            var texture_2x1 = preload("res://Assets/Art/Objects/Parcels/2x1.png")
            var texture_2x2 = preload("res://Assets/Art/Objects/Parcels/2x2.png")
            var texture_3x1 = preload("res://Assets/Art/Objects/Parcels/3x1.png")
            var clicked = false
            var filled_slots = 0
            var volume = 1
            var size = Vector2(128,128)
            signal parcel_dropped(node)
            var start_position = Vector2(0,0)
            var return_to_sender = false
            
            # Called every frame. 'delta' is the elapsed time since the previous frame.
            func _physics_process(delta):
            	if clicked and not return_to_sender:
            		global_position = lerp(global_position, get_global_mouse_position(), 25 * delta)
            	if return_to_sender:
            		global_position = lerp(global_position, start_position, 25 * delta)
            		if global_position.distance_to(start_position) < 1: return_to_sender = false
            		
            func _enter_tree():
            	global_position = start_position
            
            #func _ready():
            #	$Area2D/CollisionShape2D.get_shape().set_size(size)
            #	print(size)
            
            func _on_area_2d_input_event(viewport, event, shape_idx):
            	if Input.is_action_just_pressed("lclick"):
            		clicked = true
            	if Input.is_action_just_released("lclick"):
            		parcel_dropped.emit(self)
            		clicked = false
            
            func set_parcel_type(type = "1x1"):
            	print("setting my parcel type to " + str(type))
            	var tex = $Texture
            	var shape = $Area2D/CollisionShape2D
            	if type == "1x1":
            		tex.texture = texture_1x1
            		tex.offset.x = 0
            		shape.position.x = 0
            		size = Vector2(128,128)
            		volume = 1
            	if type == "2x1":
            		tex.texture = texture_2x1
            		tex.offset.x = 64
            		shape.position.x = 64
            		size = Vector2(258,128)
            		volume = 2
            	if type == "3x1":
            		tex.texture = texture_3x1
            		tex.offset.x = 128
            		shape.position.x = 128
            		size = Vector2(384,128)
            		volume=3
            	if type == "2x2":
            		tex.texture = texture_2x2
            		tex.offset.x = 64
            		tex.offset.y = 64
            		shape.position.x = 64
            		shape.position.y = 64
            		size = Vector2(258,258)
            		volume=4
            	shape.get_shape().set_size(size)
            	print(shape.get_shape().get_size())
            
            func _on_area_2d_area_entered(area):
            	if area.is_in_group("slot"):
            		filled_slots += 1
            		print("Width: " + str($Area2D/CollisionShape2D.get_shape().get_size()))
            		if not clicked and filled_slots < volume:
            			return_to_sender = true
            		print(filled_slots)
            
            
            func _on_area_2d_area_exited(area):
            	if area.is_in_group("slot"):
            		filled_slots -= 1
            		print(str(filled_slots))
            		if not clicked and filled_slots < volume:
            			return_to_sender = true
            • @SparksTheGamer Collision shape is a resource. It needs its local_to_scene flag set to true in order for it to be duplicated for each scene instance. Otherwise all of the instanced scenes will hold the reference to the same resource object, hence they will all appear to have values set to what was assigned last.