Assigning a value to a scene instance

Godot Version

4

Question

Hi,

I’m trying to assign a unique value to each instance of a scene - in this case a mailbox number.

I’m using a global script to get that number and then compare it to another number in another script. This all works fine.

The problem I’m having is the unique value for the variable is only available within the script for that scene. When I try to access it from another script it changes and I’m not sure why.

I’ve tried to create an export variable and change the value there but this doesn’t get passed either. It seems to default to the highest number I input into the export variable space in the inspector and assigns that to every instance of the mail box.

I’m new to godot and coding so I’m unsure what exactly I’m doing wrong. Any help is greatly appreciated.

image

This works fine. When I print out the box numbers it all works.

But here, when I print out the box number, it has changed to the highest value I have put into the inspector.

It looks like you are always changing the the singular global object’s boxNumber, so you’re always only going to see the value of assignedBoxNumber.

Thanks!

Ok, how do I just set the values? The values will never change.

From what I understand (which must be wrong) is that when the ready function runs, it runs the assignBoxNumber function which should set the values. And it should only do that once. But that is obviously incorrect so I’m not sure what to do.

So, to anyone who has a similar problem in the future… It turns out it took a lot more code (for my solution anyway) to be able to assign unique values to each of the instances. Far too much to post here. So good luck :slight_smile: