0 votes

im just trying to have a function be called when pressing left or right and when jumping, but it gives me the error in question. here is the related code:

func give_xp (amount):

LegExp += amount

if LegExp >= NextLegLevel:
    level_up()

func level_up ():

var overflowXp = LegExp - NextLegLevel

NextLegLevel *= LevelIncreaseRate
LegExp = overflowXp
LegLevel += 1

func _physics_process(_delta):


motion.y += Grav
if motion.y > MFS:
    motion.y = MFS


if facing_right == true:
    $AnimatedSprite.scale.x = 1
else:
    $AnimatedSprite.scale.x = -1

motion.x = clamp(motion.x,-MS,MS)

if Input.is_action_pressed("right"):
    motion.x += Acc
    facing_right = true
    give_exp(amount)
elif Input.is_action_pressed("Left"):
    motion.x -= Acc
    facing_right = false
    $AnimatedSprite.play("Walking")
else:
    motion.x = lerp(motion.x,0,0.2)
    $AnimatedSprite.play("Idle")

adding giveexp(amount) into if Input.isaction_pressed("right"): is when I get the error

Godot version 3.2.3
in Engine by (12 points)

2 Answers

+1 vote

Your function have name give_xp, while you are trying to call give_exp function. So either name your function give_exp or call it by give_xp(amount)

by (1,650 points)

i tried both solutions you gave but i still get the error. it doesnt like the 'amount' part and if i get rid of that it then says too few arguments for the function to be called.

+2 votes

When you call a function with parameters like
do_something(param1, param2, param3, ...)

You replace the parameters with the values you want to be used.

For example in your case, you should change the parameter "amount" into an actual value as you call it.
give_exp(10)

by (21 points)

yeah that did it thanks

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.