The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I'm porting a project of mine from 2.1.4 to 3.0.

Now I've hit a very strange behavior:

Inside an autoloaded script, I preload and instantiate another script, like this:

var optionValues = preload("res://src/").new()

Inside that GlobalValues script, I declare an empty dictionary variable as a member, like this:

var _values = {}

This empty dictionary is then accessed in functions of the GlobalValues script, like this:

# Set a value
func set(key, value):
    _values[key] = value

This results in an error, as _values is Null and not, as one would expect, a "Dictionary{0}". Worked fine in 2.1.4, of course.
_values is never set to Null and I tried declaring an empty dictionary in the autoloaded script itself, which works fine, so it's not like anything is wrong with "= {}".

So my guess is there has been some change to preload that I'm not aware of (there should really be a 2.1.4 -> 3.0 porting guide, btw...) or this is a bug - in which case I'll report it on github later.

in Engine by (57 points)
edited by

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.