This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I've been trying to make this code work for the past couple of days, but i can't pinpoint exactly why it's not working:

extends LineEdit

var GridSize_Range = range(1,99)

var NT = 1

onready var GridGenerator_Script = load("res://Scripts/Grid_Size_UI.gd")

func _on_LineEdit_text_entered(new_text):
    if new_text.is_valid_integer():
            NT = str(new_text)
            for i in GridSize_Range:
                var i2 = str(i)
                if NT == i2:
                    GridGenerator_Script.ValidGridSize == true
                    self.clear()
    else:
        GridGenerator_Script.ValidGridSize == false
        self.clear()

The Boolean (on another script):

var ValidGridSize = false

This is supposed to make so that the boolean ends up being true or false depending on user input.

but when i test it by writing something it gives me this error:

Invalid Get Index 'ValidGridSize' (on base: 'GDScript).

Why is the code not working?

Godot version Godot 3.2.3
in Engine by (34 points)

2 Answers

+1 vote
Best answer

You have to create an instance of the packed class:

onready var GridGenerator_Script = load("res://Scripts/Grid_Size_UI.gd").new()
by (1,311 points)
selected by

It worked! Thanks for the answer

+1 vote

Why are you using double equals in this situation? When you write: GridGenerator_Script.ValidGridSize == true
this simply returns a True or a False value, and you seem to do nothing with it...

To affect a value, you would simply use the equal sign (=).
GridGenerator_Script.ValidGridSize = true

But anyway, once you loaded your script, it needs to be instantiated in order to use it dynamically. When you use the load function, the object is not the script itself... It's a packed class. So skysphr is right, you need to instantiate it with the .new() method.

Then, do not forget to change your double equals for equals, and everything should work!

PS: If you didn't want to instantiate the script in order to use it like a global script, you should really read about Singletons. This way, the script is instantiated once (for all the game) and you still can play with its values.

Math

by (46 points)

I'll make sure to read about them

Also, thanks for reminding me about the (==), i left them in there accidentally because i was testing how to make the code work, if you hadn't pointed this out i'd probably still be scratching my head looking for a way to make this script work, so thanks a lot for the answer

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.