Solved Am I being stupid?

Discussion in 'Spigot Plugin Development' started by GeorgeeeHD, May 18, 2016.

  1. So I'm trying to make a gambling game where you bet on which colour of sheep will die first. Basic code of spawning sheep is here. I have debug messages throughout outputting the size of the 'allSheep' List. All of them say the size is 0 except for the outputs that are in red and aqua (lines 33 and 42). Why can I not see the objects in the list from outside the 'start()' method?
     
    #1 GeorgeeeHD, May 18, 2016
    Last edited: May 18, 2016
  2. If there's many entities in the world that code might get laggy iterating through them. You might want to just save a reference of the Sheep entity somewhere and then use that instead of saving the entity IDs and searching for them.
     
  3. There won't be too many entities. I originally stored it as type Sheep but I got the same error I currently have, which is why I changed it. I thought it couldn't match the Sheep with the one dying as they had different health or something. I will change it back to Sheep type. But still, why can I not see the objects stored in the List from outside of the 'start()' method? If I make the List static, I can see the objects within it from outside of the 'start()' method, but does it actually have to be static? I would prefer it not to be as I will be creating multiple instances of this class.
     
  4. Are you making a second instance when you register your listener or are you using the same class? If your listener is a new instance of the class, it's not going to have the same list as the one you're calling your start method in.
     
  5. Ah ok got, thanks for the help. Title is correct