So I literally just started learning how to use Godot. I have zero experience with scripting and have no idea how to fix the error I keep running into.
During the tutorial, I am at the part where you need to add "gameover" and "newgame". This is the script I have:
score = 0
The line "score = 0" gets highlighted in red and I get an error that reads this:
The identifier "score" isn't declared in the current scope.
I decided to move on thinking maybe something I input later would fix it, but then when I come to the end to check to make sure everything works, I am told to add a line under the _ready function as typed below:
The line with "new_game()" gets highlighted in red and I get a similar error that reads this:
The method "new_game()" isn't declared in the current class.
I typed everything in as shown and I am not sure what it is I am doing wrong nor how to declare anything. Help would be much appreciated. Thank you.
Here is the whole script for Main.gd and Player.gd where the problems occur.
export (PackedScene) var Mob
score += 1
$MobPath/MobSpawnLocation.offset = randi()
var mob = Mob.instance()
var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
mob.position = $MobPath/MobSpawnLocation.position
direction += rand_range(-PI / 4, PI / 4)
mob.rotation = direction
mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
mob.linear_velocity = mob.linear_velocity.rotated(direction)
export var speed = 400
screen_size = get_viewport_rect().size
var velocity = Vector2()
velocity.x += 1
velocity.x -= 1
velocity.y += 1
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
position += velocity * delta
position.x = clamp(position.x, 0, screen_size.x)
position.y = clamp(position.y, 0, screen_size.y)
if velocity.x != 0:
$AnimatedSprite.animation = "walk"
$AnimatedSprite.flip_v = false
$AnimatedSprite.flip_h = velocity.x < 0
elif velocity.y != 0:
$AnimatedSprite.animation = "up"
$AnimatedSprite.flip_v = velocity.y > 0
position = pos
$CollisionShape2D.disabled = false
score = 0
Starting think maybe I put something in the wrong script or misread something.