0 votes

This is the script...
~~~
extends Node

export (PackedScene) var Mob
var score

func ready():
randomize()
new
game()

func onPlayer_hit():
pass # Replace with function body.

func game_over():
$ScoreTimer.stop()
$MobTimer.stop()

func new_game():
score = 0
$Player.start($StartPosition.position)
$StartTimer.start()

func onMobTimertimeout():
# Choose a random location on Path2D.
$MobPath/MobSpawnLocation.offset = randi()
# Create a Mob instance and add it to the scene.
var mob = Mob.instance()
add
child(mob)
# Set the mob's direction perpendicular to the path direction.
var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
# Set the mob's position to a random location.
mob.position = $MobPath/MobSpawnLocation.position
# Add some randomness to the direction.
direction += randrange(-PI / 4, PI / 4)
mob.rotation = direction
# Set the velocity (speed & direction).
mob.linear
velocity = Vector2(randrange(mob.minspeed, mob.maxspeed), 0)
mob.linear
velocity = mob.linear_velocity.rotated(direction)

func onScoreTimer_timeout():
score += 1

func onStartTimer_timeout():
$MobTimer.start()
$ScoreTimer.start()
~~~
This is the image...

in Engine by (24 points)

1 Answer

+1 vote
Best answer

You haven't assigned a value to the Mob variable:

export (PackedScene) var Mob

As the instructions say:

Click the Main node and you will see the Mob property in the Inspector under "Script Variables".

You can assign this property's value in two ways:

  • Drag Mob.tscn from the "FileSystem" panel and drop it in the Mob property .

  • Click the down arrow next to "[empty]" and choose "Load". Select Mob.tscn.

by (20,897 points)
selected by

Ok. Thank you very much.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.