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:
queue_free()

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

func getdirection() -> Vector2:
return Vector2(
Input.get
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,
is
jumpinterrupted: bool
) -> Vector2:
var out: = linear
velocity
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
velocity
out.y = -impulse
return out

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

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.