0 votes

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 weatherreport =preload("res://WeatherReport.gd")
var geo =['HK','USA'....]
var temp=['humid','snow'....]
var weather

func _ready():

func CreateWeatherReports():
for _ city in geo:
for _ status in temp:
var weatherreport= weatherreport.new(city,status)
_ city.weatherreports.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!

Godot version 3.2.3
in Engine by (12 points)

1 Answer

+1 vote

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 --


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

by (329 points)
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.