Hi, I was wondering how I would access another scoreboard, as well as its objectives from another class and method. Thanks
What do you mean, another class or another method? You would pass it around via constructor/method parameters like any other value. Sponge does not provide a named registry of scoreboards; you are expected to manage access yourself.
Thanks for the reply but I managed to figure out a different way which simply involved me recreating the scoreboard whenever I wanted to use it.
That’s definitely performance-intensive. Why not just keep an instance of it for easy use?
I’m not great with instances or methods, how exactly would I create an instance of it?
… how are you creating them in the first place?
And what do you mean, you’re not good with methods? Knowledge of Java, object-oriented design, and programming flow is definitely a prerequisite to Sponge development.
I do have knowledge of java, and ever since I learned iv never been great at creating methods, i don’t know why. To create the scoreboard I’m using creating a scoreboard builder to build a scoreboard, add methods, and apply it to a player
Well, methods are where 100% of Java’s actual logic takes place - everything else is just structuring and storage. So it would be a good idea to get good at them.
Regardless, a good way to allow other classes to view a shared value would be to store it as a member variable in your plugin class, and to reference your plugin’s instance in the other class to retrieve that value.
In the future, please try to be able to recognize when it’s a Sponge question, and when it’s a Java question. In this case, it’s a Java question. There is nothing special about a Scoreboard; it’s a value, just like anything else. Thus, the question would be ‘how can I access a value from one class in another class?’. This forum is for Sponge questions; Java questions belong on Stack Overflow.
I know how I would access methods and variables and such from one class to another, my problem is that my scoreboard is first created when a certain event is fired, how would I take that same scoreboard out of the event method
you would put it in a member variable? or call a setter method?
So it worked, I’m not sure what I was thinking, I kept thinking that I needed to do it differently, thanks for the help