This site requires JavaScript, please enable it in your browser!
Greenfoot back
Bennylit
Bennylit wrote ...

2025/1/30

VERY COMPLICATED - Loading Zones somehow losing references to final variables?!

1
2
Bennylit Bennylit

2025/1/30

#
danpost wrote...
Everything seems to look okay as far as the code. I am not sure why (or how) the value of the static final fields could be changed to a null value.
Yes, that’s about the same thought process as I had. I think when I get the opportunity, I’m just going to upload the entire code, so maybe you could pinpoint where the problem occurs.
Bennylit Bennylit

2025/1/31

#
I have found the problem, and for documentation purposes, I will share what I did to fix it. The problem was that when creating the rooms, even though they were final, some rooms were created before others. For example, this was the code for creating the final static rooms:
public ActorPoint[] loaders;
    public GreenfootImage background;
    final static Room roboticsRoom = new RoboticsRoom();
    final static Room roboticsBackroom = new RoboticsBackroom();
    static Room soudRoom = new SoudRoom();
    final static Room roboticsHall = new RoboticsHall();
You might notice that roboticsRoom is created before roboticsBackroom, but roboticsBackroom is put into roboticsRoom, meaning there is a point in which a final value is null (because it hadn't been created yet), and it was getting passed to the room. The reason this also happened with the numeric solution that Danpost suggested was because the room, even when referenced elsewhere, was still not yet created, meaning it had a null value. I fixed this by adding a part in the code where the actor was deployed, to get the room's loading zones separately, as opposed to in the creation of any given room. Anyways, quite the adventure, I thank you, and I take my leave.
You need to login to post a reply.
1
2