For...in...array problem

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By alanmung2

Hi, I am a very new programmer and just started to learn how to use Godot. Sorry if my questions are very naive.

I have defined two array as follow,

var geo =[‘HK’,‘USA’…]
var temp=[‘humid’,‘snow’…]

And in the end I would like to generate an array like this,

var weather_reports = {‘HK’:[‘humid’,‘snow’,…] , ‘USA’:[‘humid’,‘snow’,…],…}


For this, I have created a node called WeatherReport in which I have declared these variables;

var city= “null”
var status = “null”

func _int(_city,_status):
city= _ city
status= _ status

Then in my Main.gd ;

var weather_report =preload(“res://WeatherReport.gd”)
var geo =[‘HK’,‘USA’…]
var temp=[‘humid’,‘snow’…]
var weather_reports=

func _ready():
CreateWeatherReports()

func CreateWeatherReports():
for _ city in geo:
for _ status in temp:
var _weatherreport= weather_report.new(_city,_status)
_ city.weather_reports.append[_weatherreport]

It appears that there is an error in the bolded script saying 'Invalid call to function ‘new’ in base ‘GDScript’.

Can anyone point out what’s the problem or if my whole logic got completely wrong?

Thanks a lot!

:bust_in_silhouette: Reply From: Bean_of_all_Beans

Just looking at this, you misspelled _init as _int. In order for the new method to work, you need to define _init.

Also, the next line down –

_city.weather_reports.append[_weatherreport]

– should use parenthesis instead of square brackets. It should look like this:

_city.weather_reports.append(_weatherreport)