0 votes

Can't get to resolve the issue Unexpected token: if: as an error.

if Input.isactionjustpressed("uifocus_next"):
print("Creating a fireball")
var fireball = FIREBALL.instance()

asked Oct 27, 2019 in Engine by WhatAmIDoingHere (31 points)

It looks like you haven't included enough information to diagnose the error. What comes before the if? Can you format your code properly, so that it's apparent whether the indentation is correct?

extends Actor

const FIREBALL = preload("res://Buttons/game/Fireball.tscn")

export var stomp_impulse = 2000.0

func onEnemyDetectorareaentered(area: Area2D) -> void:
velocity = calculatestompvelocity(velocity, stomp_impulse)

func onEnemyDetectorbodyentered(body: PhysicsBody2D) -> void:

func physicsprocess(delta: float) -> void:
var isjumpinterrupted: = Input.isactionjustreleased("jump") and _velocity.y < 0.0
var direction: = get
velocity = calculatemovevelocity(velocity, direction, speed, isjumpinterrupted)
velocity = moveandslide(velocity, FLOOR_NORMAL)

func getdirection() -> Vector2:
return Vector2(
actionstrength("moveright") - Input.getactionstrength("moveleft"),
-1.0 if Input.is
actionjustpressed("jump") and isonfloor() else 0.0

if Input.isactionjustpressed("uifocus_next"):
print("Creating a fireball")
var fireball = FIREBALL.instance()

func calculatemovevelocity(
linearvelocity: Vector2,
direction: Vector2,
speed: Vector2,
jumpinterrupted: bool
) -> Vector2:
var out: = linear
out.x = speed.x * direction.x
out.y += gravity * getphysicsprocessdeltatime()
if direction.y == -1.0:
out.y = speed.y * direction.y
if isjumpinterrupted:
out.y = 0.0
return out

func calculatestompvelocity(linearvelocity: Vector2, impulse: float) -> Vector2:
var out: = linear
out.y = -impulse
return out

func onEnemyDetectorbodyshapeentered(bodyid: int, body: PhysicsBody2D, bodyshape: int, areashape: int) -> void:

1 Answer

+1 vote
Best answer

Your code still isn't formatted correctly. There's a button to format code when you edit your post. It looks like {}.

However, I can see I think that your if statement is not indented at all. It must be inside a function to parse correctly.

answered Oct 27, 2019 by kidscancode (17,714 points)
selected Oct 27, 2019 by WhatAmIDoingHere
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 How to use this Q&A? before posting your first questions.