Function to variable

Godot Version

4.2

Question

How do i make a variable like a function, i am trying to make a game when godot wants me to use a variable instead of a function but i now made the variable nil and it does nothing

not quite clear what did you want, to access variable or function just use “.” or the function/variable name. what’s wrong with that

need to fix this
image

really what this post said, need to see your code what’s happening there else really difficult to figure out what is the problem

func _process(delta):
	var fire
	var Bullet_instance = Bullet.instantiate()
	Bullet_instance.position = get_global_position()
	Bullet_instance.rotation = rotation_degrees
	Bullet_instance.apply_impulse(Vector2(),Vector2(bullet_speed, 0).rotated(rotation))
	get_tree().get_root.call_deferred("add child", Bullet_instance)
	await get_tree().create_timer(0.4).timeout
	can_fire = true
	if Input.is_action_just_pressed("Fire"):
		fire

should be “add_child”

is this snippet from a working code?

it works except the variable part

which makes it crash :confused:

ye, dunno what happened there, need to see whole code
also which line from this has the error?

extends Sprite2D

var can_fire = true
var Bullet = preload("res://bullet.tscn")
var bullet_speed = 5000

func _ready():
	pass
	set_as_top_level(true)
	
	
func _physics_process(_delta):
	pass
	position.x = lerp(position.x, get_parent().position.x, 0.5)
	position.y = lerp(position.y, get_parent().position.y + 10, 0.5)
	var mouse_pos = get_global_mouse_position()
	look_at(mouse_pos)
	
func _process(delta):
	var fire
	var Bullet_instance = Bullet.instantiate()
	Bullet_instance.position = get_global_position()
	Bullet_instance.rotation = rotation_degrees
	Bullet_instance.apply_impulse(Vector2(),Vector2(bullet_speed, 0).rotated(rotation))
	get_tree().get_root.call_deferred("add_child", Bullet_instance)
	await get_tree().create_timer(0.4).timeout
	can_fire = true
	if Input.is_action_just_pressed("Fire"):
		fire

nice, but which line the error said?

i tried to put the whole code to my godot 4.2.1:

you sure it’s already working?

well this is now the error i get
image

Saw your another post of yours today. While you can and welcome to post 1000 questions here if you’d like, I will say with utmost respect and love - the far easier solution is to pick up a beginner-level book on programming. There’s definitely a place for trial & error, but without some foundation of theory under your belt, that trial & error is 10x as hard and very inefficient.

In your code, for example, you do:

var fire

if Input.is_action_just_pressed("Fire"):
	fire

A book on programming will teach you variables vs functions and why that last line won’t work (this is where your lambda error message is coming from, I’d imagine). You’ll also easily understand errors like “nonexistent function ‘apply_impulse’”.

It may seem like a detour, but it’s in fact it’s the fastest route if you’d like to make game dev your career.

haha im getting that error now too