4.2.2
Hi everyone,
I have the Spring in Your Step example posted earlier, and it is known to have the func start(pos): function working correctly, but when I use the example again in a new, different project themed on Halloween, I get told “Expected indented block after function declaration” even though I typed it correctly the same exact way as the first time.
Can someone please explain to me what I am doing wrong this time?
Link to Halloween Game
“Expected indented block after function declaration” usually means that there is a missing indention. Check that you are using “Tab” and NOT spaces for your indention.
1 Like
Now I get “Standalone lambdas cannot be accessed. Consider assigning it to a variable.” At the func start(pos): line.
In the example I am using (from the Spring in Your Step Project), I did not do anything like that, it worked fine as is; how should I change it in particular?
Can you please shear the code?
Will do; only the snippet that isn’t working.
extends Area2D
class_name Player
@onready var _animation_player = $AnimationPlayer
@export var speed: float = 400 # how fast the player will move in pixels per second.
var screen_size: Vector2 # size of the game window.
# Called when the node enters the scene tree for the first time.
func _ready():
screen_size = get_viewport_rect().size # Get size of viewport rectangle.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if (Globals.playerbounceheight >= 0) and (Globals.playertouchingplatform == true):
position.y -= (Globals.playerbounceheight) * delta
Globals.playerbounceheight -= 5
else:
position.y += 120 * delta
func start(pos):
position = pos
show()
This is the original example.
extends Area2D
class_name Player
@onready var _animation_player = $AnimationPlayer
@export var speed: float = 400 # how fast the player will move in pixels per second.
var screen_size: Vector2 # size of the game window.
# Called when the node enters the scene tree for the first time.
func _ready():
screen_size = get_viewport_rect().size # Get size of viewport rectangle.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
func start(pos):
position = pos
show()
This is the version that says it doesn’t work.
The start function is not evening being called in the process function.
Under the process function call the start(pos)
Tried that, and got the older error about “expected indented block” etc I reported above.
What gives, if I get errors that contradict each other either way I go?
Are you sure you indented with tabs.
I thought that indenting it would consider it as inside the function rather than under it, like you just told me to not include it in the function cause it’s not like that in the original example.
When you create your functions the are not called because they are custom, they only function are running during the game are the build-in functions like _ready() and _process().
For you to be able to call your own functions they need to be called by one of the build-in functions, in your case it would be _process().
Okay, so I should indent it to be called inside the function?
This is really bizarre, but is that what you think I need to do in this case?
Yes, put it under the _process() and indent it ONE TAB.
And drum roll please… I get told “Standalone lambdas cannot be accessed” etc after hitting the tab button one time, the second error I mentioned above.
What should I change?
Idk whats going on, can you please just send me the godot file?
Okay, will do. Click on the attachment at the top post for the latest updated version of the game.
I just dont understand whats going on, why doesnt the player movement code? and why are you using animtion node if your not even playing the animation?
I was just copy-pasting player movement that was given to work from one platformer game to another platformer game.
ok, can you explain what is the game about, like logic and other stuff