Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Andromachus |
I’m currently following along with the “Coin Dash” project as provided in the “Godot Engine Game Development Projects: Build five cross-platform 2D and 3D games with Godot 3.0” book. and I keep running into an Invalid set Index error. The code in question looks as follows:
extends Node2D
export (PackedScene) var Coin
export (int) var playtime
var level
var score
var time_left
var screensize
var playing = false
func _ready():
randomize()
screensize = get_viewport().get_visible_rect().size
$Player.screensize = screensize
$Player.hide()
new_game()
func new_game():
playing = true
level = 1
score = 0
time_left = playtime
$Player.start($PlayerStart.position)
$Player.show()
$GameTimer.start()
spawn_coins()
func spawn_coins():
for i in range(4 + level):
var c = Coin.instance()
$CoinContainer.add_child(c)
c.screensize = screensize
c.position = Vector2(rand_range(0, screensize.x),rand_range(0, screensize.y))
The error occurs at line 32(c.screensize = screensize), with the following error message: "Invalid set index ‘screensize’ (on base: ‘Area2D (Coin.gd)’) with value of type ‘Vector2’. I’m still rather new at this but I’m unsure what exactly is wrong, is the fact that screensize is a vector causing the issue? Any help would be greatly appreciated.
Did you define var screensize
in the coin’s script?
kidscancode | 2020-03-01 09:04