Cleaning a Code in gdscript 3.1

Hello, Wonderfull Godot Teachers (and colleagues)!

First and foremost - Thank you for your Job! I’m a absolute beginner in coding, and as beginner I will say it is a very good introduction to starting it. I think I started to getting it finally (I’m begginner but it not mean I was never trying to learn coding).
I know course is meant for pre 3.1 version, but it is just around the corner, so I tried to give it a go. And it was all nice and easy, till this moment. I’m almost sure, that there is something I should make different to make code working on 3.1…

I was looking in documentation, and on this forum. @ShadeWolfDK made his own working version, but it’s bit different, (he is using signals) so it’s no help for me (at least for now)

so all I can get now from Godot is:

func update(motion)

  • / Parse Error: Function signature doesn’t match the parent. Parent signature is: ‘void update()’.

When I delete “motion” i get different error.

func update()
Parse Error: Identifier ‘motion’ is not declared in the current scope.

I hope it is something trivial, and will not need to come back to 3.0.6.
And i just copied source from github, so it is not a some kind of stupid typo from my side.

Thank you again and waiting for an answer!

Adam

Does your script inherit from another one ?
I dont really remember about this section, but if your parent scripts have the same function, but not with the same parameter, it could throw an error like this one.

Example… You have a Player.gd who extends from Character… If your Character has a update() function, your player.gd needs to have the same fonction, so it will not take the motion parameter.

@GrossePistache Thanks for an answer. Yes, script inheriting form another one, that’s a part of a course when it is introduced. What you suggest sounds reasonable, but didn’t give me a result.

after a while

So today I will carefully watch this lesson again :blush:

after even more while

Ok… I step by step rewatched a lesson. And I’m 99% sure, that there is no typo in my code. (But I admit, that as I can very fast see “resonsibility” in last Juan Linietsky post I’m not that fast to find typos in code for now. In fact I’m very slow in it) So i decide to not fight with it - I just have it all in one script, but I made individual functions for animation and motion, so it is more less what was a point of a lesson.

it goes like this:

extends KinematicBody2D

var motion = Vector2()
const SPEED = 180
const GRAVITY = 1000
const UP = Vector2(0,-1)
const JUMP_SPEED = -400

func _physics_process(delta):
	update_motion(delta)
	
func _process(delta):
	update_animation(motion)

func update_motion(delta):
	fall(delta)
	run()
	jump()
	move_and_slide(motion, UP)
	
func fall(delta):
	if is_on_floor():
		motion.y = 0
	else:
		motion.y += GRAVITY * delta

func run():
	if Input.is_action_pressed("ui_right") and not Input.is_action_pressed("ui_left"):
		motion.x = SPEED

	elif Input.is_action_pressed("ui_left") and not Input.is_action_pressed("ui_right"):
		motion.x = -SPEED
	
	else: 
		motion.x = 0
	
func jump():
	if Input.is_action_pressed("ui_up") and is_on_floor():
		motion.y = JUMP_SPEED

func update_animation(motion):
	if motion.y < 0:
		$AnimatedSprite.play("idle")
	elif motion.x < 0:
		$AnimatedSprite.play("move")
		$AnimatedSprite.flip_h = false
	elif motion.x > 0:
		$AnimatedSprite.play("move")
		$AnimatedSprite.flip_h = true
	else:
		$AnimatedSprite.play("idle")

I startet this course in Godot 3.1 Beta from the beginning and thought i could go through with this. Up until now, everthing was fine, but now i have the same error you have. I think I found the reason for that in the changelog: “Shadowing variables from parent scopes is no longer allowed in GDScript.”

So I guess we need a different solution. How does this signaling work?

I tried to follow this tutorial with Godot 3.1 too, and was stuck with the same error.
I asked for help on Godot’s Discord, and here’s the reason:
update() is a built-in function (used in Canvasitem) so the name of our function collides with it.
Rename your function to something else, like “updating()” and it should work.

7 Likes

I was waiting for some update (pun not intended) to course to godot 3.1 to continue further, but you speed up this process. Thank you very much!

Thanks, @Phildjii. That fixed it for me, much appreciated!

@Phildjii Many Thanks

yea, would have definitely be nicer to have a clearer error or warning for methods already defined within parent classes.

glad you managed to suss it out and get it working again.

thank you very much phil, what channel are you in? i want be in it if it’s possible

Woah, that was two years ago, I can’t remember which channel :slight_smile: I don’t hang out on Godot’s official Discord these days, but there is a “General help” section with a “Beginner” channel that seems appropriate.

There is a Godot channel on our Discord server as well, link is in the page footers, like at the bottom of the about page.

https://discord.com/invite/gamedevtv

ill close this thread as its a couple years old now.

DaZ

Privacy & Terms