mteb/FreshStackRetrieval huggingface dataset:
The following scripts job is to scan the given directory and find out how many files(or characters) are in it. Then it creates a number of buttons equal to the total number of files. Currently my problem is that i have no way knowing which button is pressed during run time.
extends Control

#number of characters to be imported
var characters = 0
#file names of all avalible chararters
var files = []
#buttons associated with said characters
var array = []

# Called when the node enters the scene tree for the first time.
func _ready():
    scan_directory()
    populate()
    setup()

#scans for the number of characters in the folder
func scan_directory():
    var current = ""
    var dir = DirAccess.open("res://Characters/")
    dir.list_dir_begin()
    current = dir.get_next()
    while current != "":
        files.push_back(current)
        current = dir.get_next()
    print(files)
    characters = files.size()

func setup():
    var x = 0
    for i in characters:
        var but = array[x]
        var path = "res://Characters/" + files[x] + "/"+ files[x] + ".gd"
       var char = load(path)
       var dic = char.import()
       x += 1

#creates buttons equal to the number of characters
func populate():
    var x = 100
    var y = 100
    var texture = Texture2D.new()
    texture = load("res://img/button.jpg")

    for i in characters:
        var but = Button.new()
        var path = load("res://Scripts/Character_Select.gd")
        add_child(but)
        but.pressed.connect(self.export)
        but.set_position(Vector2(x,y))
        but.set_button_icon(texture)
        x += 250
        if x > 1250:
            x = 100
            y += 250
        array.push_back(but)
    print(array)

func export():
    var temp = self.get_instance_id()
    print("Current id: " + str(temp))

So im currently looking for a way to either have the button pass a varible when clicked or be able to know the instance id of the button that was clicked so i can compare it to know buttons in the array.
Any help is appreciated.
While trying to host my video game made with Godot 4 with Flask, I've ran into a problem-- the game doesn't load, and instead there is a spinning circle.
The error messages are as follows:
GET http://127.0.0.1:5000/game/index.worker.js net::ERR_BLOCKED_BY_RESPONSE 200 (OK) (or 302 when not hard-reloading the page)
Unchecked runtime.lastError: The message port closed before a response was received.
and also a repeating set of errors:
index.js:14010 still waiting on run dependencies:
onPrintError @ index.js:14010
(anonymous) @ index.js:737
setInterval (async)
addRunDependency @ index.js:727
createWasm @ index.js:886
(anonymous) @ index.js:12933
(anonymous) @ index.js:14253
Promise.then (async)
(anonymous) @ index.js:14251
doInit @ index.js:14250
init @ index.js:14267
startGame @ index.js:14366
(anonymous) @ (index):224
(anonymous) @ (index):244
index.js:14010 dependency: wasm-instantiate
onPrintError @ index.js:14010
(anonymous) @ index.js:739
setInterval (async)
addRunDependency @ index.js:727
createWasm @ index.js:886
(anonymous) @ index.js:12933
(anonymous) @ index.js:14253
Promise.then (async)
(anonymous) @ index.js:14251
doInit @ index.js:14250
init @ index.js:14267
startGame @ index.js:14366
(anonymous) @ (index):224
(anonymous) @ (index):244
index.js:14010 (end of list)

The output from Flask looks like this:
127.0.0.1 - - [22/Jun/2023 09:37:40] "GET /game/index.FILE.EXTENSION HTTP/1.1" 200 - where FILE and EXTENSION are exactly what they sound like.
The code for the website is as follows:
from flask import Flask, send_from_directory

app = Flask(__name__)

@app.route('/<game>/')
def index(game):
    response = send_from_directory(f'./{ game }', 'index.html')
    response.headers.add('Cross-Origin-Opener-Policy', 'same-origin')
    response.headers.add('Cross-Origin-Embedder-Policy', 'require-corp')
    return response

@app.route('/<game>/<file>')
def game(game, file):
    return send_from_directory(f'./{ game }', file)

app.run()

and the filesystem looks like this:

(it was exported as index.html, but is the same with a proper name)
Also, when just opening up the file as a static website, it just states that it needs Cross Origin Isolation, so I can't test it there. The build does run fine on itch.io
The Unchecked runtime.lastError message was caused by an extension according to this, so I opened up a different browser without extensions, and that was gone! The others were still there, and I can't find anything on how to fix this.
Now, the official documentation sadly only reads:

void draw_texture_rect_region ( Texture2D texture, Rect2 rect, Rect2 src_rect, Color modulate=Color(1, 1, 1, 1), bool transpose=false, bool clip_uv=true )


Draws a textured rectangle region at a given position, optionally modulated by a color. If transpose is true, the texture will have its X and Y coordinates swapped.

I would like to ask what the parameter Rect2 src_rect does.
I am trying to draw a repeating texture into a CanvasItem (a button) and am trying to use the CanvasItem.draw_texture_rect_region() method to do so.
Specifically, my function looks like this:
# size_in_cells is the amount of grid cells the object is supposed to use.

# cell_size is the side length of the (square) cell

# blockTexture is the CompressedTexture2D I am using as a texture. As it has a native resolution of 
# 64 by 64 pixels I need to scale it to match the cell_size.

func _draw():
    for i in range(size_in_cells):
        draw_texture_rect_region(blockTexture, \
        Rect2(Vector2((self.get_rect().size.x/size_in_cells)*i,0), Vector2(cell_size, cell_size)),\
        self.get_rect())
In this documentation: https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/shading_language.html#uniforms I see several examples of how to use hint but I don't know how to set a default value when I use a hint
I have tried:
uniform float mask_scale = 1.0 : hint_range(0.1, 10.0);

But I got error:

Expected expression, found 'HINT_RANGE'
I'm making a 2.5D tower defense game with bloons in Godot.
(All code and scenes are on my github). (Also I fixed my git so the repo is working now)
My Bloon scene consists of a Node3D and a Sprite3D for the Bloon, and when I instantiate the Bloon (in code) the Node3D and Sprite3D are in the scene tree, but it doesn't show the sprite.
I tried changing the sprite after instantiating the scene, but still nothing. I also tried hiding all other objects, but still, nothing. J was expecting that the Bloon sprite would show at 0,0,0 but it didn't.
So I have a game I'm making and I'm making a dash mechanic. I have a player class that the player nodes (that are character2D nodes) inherit from. I (mostly) made it so the player needs to have a dash bar filled up so they can dash. I need to have a signal that resets the players dash meter, and it will connect, but it won't run the function. (I'm using Godot 4.0)
Character2D Script
func _ready():
    player.remove_dash.connect(_remove_all_dash)
    print("is connected: " + str(player.remove_dash.is_connected(_remove_all_dash)))
    
func _remove_all_dash():
    dash_power = 0
    print("function ran")

Player class script
func check_for_dash_input(delta, player_resource: Resource, dash_timer: Timer, input: String, dash_power: int):
    dash(delta, player_resource, dash_timer, dash_power)
    
        if Input.is_action_just_pressed(input):
        dash_timer.start()
            emit_signal("remove_dash")
            print("signal emit")

Debug console:
is connected: true;
signal emit
I tried looking a the docs for Godot 4.0, but that didn't really help.
I switched from Godot 3 to Godot 4 and was trying to make a platforming game.
I need the export(Resource) function, but it no longer exists/functions in the new Godot.
What's the equivalent of the function, but in Godot 4?
(language is GDScript)
I'm creating a game using Godot Engine and I can't figure out how to create a wall to prevent a player from walking out of the screen.
The player is able to walk out of the screen window. How do I prevent it from happening?
I tried to use the CollisionShape2D node but I don't think I know how to use it properly in a way that it works like I want it to.
I'm currently making a game, and I want my character to shoot projectiles at the enemy. I'm facing an issue where when I click, the bullet doesn't fire. Here's my code so far:
public partial class PotatoCannon : Sprite2D
{
    public Timer cooldown;

    [Export]
    public PackedScene boolet { get; set; }

    public override void _Ready()
    {
        cooldown = GetNode<Timer>("CannonCooldown");
        cooldown.Autostart = false;
    }
    public override void _PhysicsProcess(double delta)
    {
        GD.Print(cooldown.TimeLeft);
        LookAt(GetGlobalMousePosition());
        RotationDegrees = Math.Abs(RotationDegrees);
        if (RotationDegrees%360>=90.0 && RotationDegrees%360<=270.0)
        {
            FlipV = true;
        }
        else
        {
            FlipV = false;
        }
        if (Input.IsActionJustPressed("shoot") && cooldown.TimeLeft == 0)
        {
            bullet Bullet = boolet.Instantiate<bullet>();
            this.AddChild(Bullet);
            cooldown.WaitTime = 1;
            cooldown.Start();
        }
    }
}

oh and btw, the error message is
E 0:00:49:0157   PotatoCannon.cs:24 @ void PotatoCannon._PhysicsProcess(Double ): System.NullReferenceException: Object reference not set to an instance of an object.
`extends Node2D

const SlotClass = preload("res://Inventory/Slot.gd")
@onready var inventory_slots = $GridContainer
var holding_item = null

func _ready():
     for inv_slot in inventory_slots.get_children():
        inv_slot.connect("gui_input" , self , "slot_gui_input", [inv_slot])
        
func slot_gui_input(event: InputEvent, slot: SlotClass):
    if event is InputEventMouseButton:
        if event.button_index == MOUSE_BUTTON_LEFT & event.pressed:
            if holding_item != null:
                if !slot.item: # Place holding item to slot
                    slot.putIntoSlot(holding_item)
                    holding_item = null
            else: # Swap holding item with item in slot
                var temp_item = slot.item
                slot.PickFromSlot()`
                temp_item.global_position = event.global_position
                slot .putIntoSlot(holding_item)
                holding_item = temp_item
        elif slot.item:
            holding_item = slot.item
            slot.pickFromSlot()
            holding_item.global_position = get_global_mouse_position()
func _input(event):
    if holding_item:
        holding_item.global_position = get_global_mouse_position()`

I was following a tutorial for an inventory, the tutorial used Godot 3. whilst I use Godot 4.
This is the code that is giving the error ( < inv_slot.connect("gui_input" , self , "slot_gui_input", [inv_slot]) >, is giving the error)
Error

Line 9: Too many arguments for "connect()" call. Expected at most 3 but received 4.
Line 9: Invalid argument for "connect()" function: argument 2 should be "Callable" but is "res://Inventory/Item/Item.gd".
Line 9:Cannot pass a value of type "String" as "int".
Line 9: Invalid argument for "connect()" function: argument 3 should be "int" but is "String".
I have exported the web version of my Godot 4, it is in a folder on my local drive.
Because of the SharedArrayBuffer dependency I can not just double-click in the index.html file. If I do so I see this error:

Error The following features required to run Godot projects on the Web
are missing: Cross Origin Isolation - Check web server configuration
(send correct headers) SharedArrayBuffer - Check web server
configuration (send correct headers)

How can I run it in local?
in gdscript (using godot 4.1.1 stable) i am working on a function that adds a checkbox dynamically works fine
but when i try to get it to do something when it is toggled i get all sorts of errors this is my small function
func _on_add_left_button_pressed():
    var checkbox = CheckBox.new()
    var text = houseNum.text
    leftList.add_child(checkbox)
    checkbox.text = text
    checkbox.connect("toggled", self, "_on_checkbox_toggled")

currently i have the "_on_checkbox_toggled" defined above but it dosent do anything at the moment just has a print statement in it
the checkbox.connect line gives me an error that says:

Invalid argument for "connect()" function: argument 2 should be "Callable" but is "res://main.gd"

any help would be much appreciated
I had the following code inside an all_tween_completed signal:
func set_tween():
    if move_range == 0:
        return
    move_range *= -1
    var move_tween = get_tree().create_tween()
    move_tween.tween_property(self, "position:x",
                position.x + move_range,
                move_speed) \
                .from(position.x) \
                .set_trans(Tween.TRANS_QUAD) \
                .set_ease(Tween.EASE_IN_OUT)

So that after everything moved I swap sign and move to the other side. However, in Godot 4 there is no such signal. I already changed the code to accommodate for the new syntax but I am not sure how can I reproduce the previous behaviour. Do I need to keep calling and emitting the finished signal from Tween?
I want to connect the pressed signal of 9 buttons by code but since the .connect method doesn’t use a string argument (which I could easily modify in my loop) I don’t know how to connect each of them.
I want to do something like this:
for i in buttonArray:
    get_node("button%d" %i).pressed.connect("on_pressed_button_%d" %i)

Expecting it will connect the 9 pressed signals to my 9 on_pressed_button function
I found a post for an older Godot version that use only one "on_pressed" function for the whole list and get the button in the parameter.
for button in get_tree().get_nodes_in_group("my_buttons"):
    button.connect("pressed", self, "_some_button_pressed", [button])

func _some_button_pressed(button):
    print(button.name)

Is something like this still possible in the actual 4.1 version ?
I need to use this script written in godot 3 to work in godot 4
language is gdscript
extends Path2D

enum ANIMATION_TYPE {
    LOOP,
    BOUNCE,
}

export(ANIMATION_TYPE) var animation_type

onready var animationPlayer: = $AnimationPlayer

func _ready():
    match animation_type:
        ANIMATION_TYPE.LOOP: animationPlayer.play("MoveAlongPathLoop")
        ANIMATION_TYPE.BOUNCE: animationPlayer.play("MoveAlongPathBounce")
I exported the godot project to HTML5 and after uploading to itch.io I got the error Error The following features required to run Godot projects on the Web are missing: Cross Origin Isolation - Check web server configuration (send correct headers) SharedArrayBuffer - Check web server configuration (send correct headers)
I tried to export the project with different settings but still got 1 result.
I am just starting out Godot and I need a little help with some platforming code written in Godot 4
How do I set a default value to this ->
@export var speed:int: set = set_speed
The language being used in the code is gdscript
I am working through the "Squash the Creeps" 3D game tutorial in Godot and I have found that when the player character uses the move_and_slide() method in order to initiate a landing movement on top of an enemy collision mesh that it sometimes increases the score by more than 1 even if landing on only a single enemy. It appears from the debugger that calling get_slide_collision_count() as suggested in the tutorial is indicating that there was more than one collision in some instances, and iterating over the indices of the collision array (KinematicCollision3D) shows that there are multiple collisions with the same colliding object (collision.get_collider()) at the same position (collision.get_position())
My questions is whether or not this is expected behavior? I can understand that the "move_and_slide()" method for character bodies is intended to be executed to take care of multiple subsequent collisions to ensure flush movement, but is it expected that it would lead to multiple reported collisions with the same object in the same single call to move_and_slide()?
If so, I would imagine it is standard practice when using the collisions reported by move_and_slide() that the developer programs around that and ensures that when iterating over the collisions that any subsequent collisions in the array with that instance are ignored?
If not, what am I doing wrong here to generate more than one collision with the same instance? It seems like this would be something that would be noticed by SOMEONE else who is running through this tutorial but a lot of searching has left me empty handed.
(Godot 4.1.1 btw)
The following is called in the _physics_process(delta) method:
for index in range(get_slide_collision_count()):
    var collision = get_slide_collision(index)
    var collider = collision.get_collider()
    var collision_position = collision.get_position()
    if (collider == null):
        continue
    if (collider.is_in_group("mob")):
        if Vector3.UP.dot(collision.get_normal()) > 0.1:
            collider.squash() # This increments the score
            target_velocity.y = bounce_impulse

collider.squash is being called sometimes 2-3 times instead of once even if only one enemy is squashed in terms of how many enemies the player is actually landing on. Debugger shows more than one collision with the same collider at the same collision_position in a single call to get_slide_collision(). I would expect every collision in the KinematicCollision3D object to be with a unique collider instance, not multiple times with the same object instance.
I am using the ConfigFile to save all the game related data into the user system.
There are two methods, one for saving the data and other one for getting the data.
Function to save the data:
func _set_data(filename: String, section: String, field: String, value):
    var config_file = ConfigFile.new()
    
    config_file.set_value(section, field, value)
    
    config_file.save(filename)

Function to get the data:
func _get_data(filename: String, section: String, field: String, default_value):
    var config_file = ConfigFile.new()

    config_file.load(filename)
    
    var result = config_file.get_value(section, field)

    if result == null:
        config_file.set_value(section, field, default_value)
        
        result = default_value
        
        config_file.save(filename)
    
    return result

Abstract functions to use these private functions outside the file indirectly:
func set_world(value: int):
    _set_data(app_config_file, world_section, world, value)

func get_world():
    return _get_data(app_config_file, world_section, world, 1)

func set_level(value: int):
    _set_data(app_config_file, level_section, level, value)

func get_level():
    return _get_data(app_config_file, level_section, level, 1)

//config file and section are basically strings

There is no issue in using these alone(for single data), but having issue in saving multiple sections at once!
For eg:
    set_level(2)
    
    set_world(4)
    
    print(get_level())
    print(get_world())

Expected output:
2
4

Actual output:
1
4

Same if I am calling save_world before and save_level after.
Research done:
Whenever I am calling another function which saved other data, then it is removing the data related to the first 'set' function called.
I was trying to make a set of Area2Ds that would display a value when the mouse is hovering over them. They're children of a control node (technically children of buttons in that node, the exact order is Control > Panel > Panel > Vbox > Hbox > Button > Area2D, yes the two panels are not a typo, no I'm not good at UI design). The control node has it's own scene where I edit it, and when I run just that scene everything works fine. The issue arises when I bring it into my main scene, everything loads correctly, but the Area2Ds no longer work. I have absolutely no idea why this is.
I've checked that the collision layers of the Area2Ds and the mouse tracker aren't somehow changed, I've confirmed that the Area2Ds aren't being deleted or moved out of place or having their collision shapes changed, I've tried changing the Mouse Filter setting in the control node since I saw someone with a (seemingly) similar issue who was able to solve it that way. No luck
Any help on figuring this out would be massively appreciated, thanks.
Alternatively, if there's a way for buttons to send a signal when the mouse is hovering over them that would also be useful.
Godot doesn't support static signals, so I tried two approaches:
Empty Signal:
static var my_signal: Signal = Signal()

Custom type:
static var my_signal: StaticSignal = StaticSignal.new()

class_name StaticSignal

var _callables: Dictionary

func connect(callable: Callable) -> void:
    self._callables[callable] = true

func disconnect(callable: Callable) -> void:
    self._callables.erase(callable)

func emit(data: Variant) -> void:
    for callable in self._callables:
        callable(data)

The problem is when it comes to .connecting to the signal. With StaticSignal I am getting a .connect member not found error. With Signal I am getting an ignored runtime error.
static func _static_init():
    ChatLog.new_message.connect(func(msg):
        if len(_log) >= LIMIT:
            _log.remove_at(0)
        _log.append(msg))
I have a area node in godot4 which can scale up and down and also rotate. there are celling, floor and wall in scene, my area node place  between them and can scale up, when this area got bigger can collide with other areas like floor, wall or celling. I want to know that area i collided  is wall, floor or celling.
I know there is characterbody node which has method that shows node which is collided is wall, floor or ceiling. but I want to use area node for both of them. how can I find node which is collided is wall, celling or floor?
Thanks in advance.
this is my code:
func my_raycast(myray:RayCast3D,myarea:Area3D):
myray.global_position = center_pivot.global_position
myray.enabled = true
myray.target_position = myarea.global_position - myray.global_position
if(myray.is_colliding()):
    if(myray.get_collider().name==myarea.name):
        #myray.enabled = false
        print("colided")
        
        var mynormal = myray.get_collision_normal()
        print(myray.get_collision_normal())
        
        if(mynormal.is_zero_approx()):
        mynormal = -myray.global_position.direction_to(myray.to_global(myray.target_position))
            
        var is_floor:bool = mynormal.angle_to(myarea.transform.basis.y/myarea.scale.y) <= PI/4
        var is_ceiling:bool = mynormal.angle_to(myarea.transform.basis.y/myarea.scale.y) <= PI/4
        var is_wall:bool = mynormal.angle_to(myarea.transform.basis.y/myarea.scale.y) <= PI/4

===============
never condition of is_zero_approx got true.
I used raycast for finding normal of node I collided but I don't have any idea, how to find answer? I don't want to use layer or tags on wall, floor and celling @Theorat
I have a scene that consists of one parent and several children, which are all Sprite2Ds, like "Body", "Clothes", "Armor", etc. I want to be able to refer to the parent as if it was a single sprite that looks like the composition of all the children sprites. So, for instance, I would like to be able to set the flip_h on the parent and have that flip all of the children. I would like to be able to refer to the texture of the parent, and have that be the image that the scene looks like, i.e., all of the sprites layered on top of each other.
I was expecting this to work just by making the parent a "Sprite2D" and adding the child sprites, but then the properties just refer to the empty texture of the parent sprite. In other posts I have seen people recommending stitching the images together in GIMP or something, but that is not going to work for me--I need control over all the behavior of all the individual layers of the overall sprite, but I want to be able to refer to the resulting sprite as if it was a single image.
I have also seen recommendations to add a camera/viewport and grab the displayed image that way, but I don't think this is a good idea in my case because I will have hundreds of these scenes and I want it to be as performant as possible.