Passing between Packages

In my project I have 3 Packages. I am sure this is just a java coding problem and not a JME3 Problem.

My Packages are:
gameCore: Handels most of the calling and threads consists mainly of the main.java file and application settings and such

levels: Handels the scenes and objects inside the game

and Mechanics: kinda obvious what this package does

Anyways, to the main issue on hand. I am trying to use the levels package with the class CommonDesignStructure.java for very common objects (lamp posts, trash cans, paralax backgrounds etc.

I cannot use rootNodes nore the assetManager in these packages(thus far I tested).

However, while trying to code it I get red flags and the only option it gives me is to make a class called rootNode and assetManager. Ussually It asks to use an import.

Any ways I can work around this?

Thanks

–Me

This might not be what you wanna hear but it is what most guys here is going to tell you;

You are trying to code a game without a proper understanding of Java and the core concepts of object oriented programming… this is the gates to a world of pain.

You will be better off by spending some time getting up to speed on programming before building a game because you are only going to waste your time fighting issues like this anyways…

I second what Kwando says. Your problem is not packages but is a basic understanding of OOP and instance variables.

When you write little toy applications with all of the code in your main class that extends SimpleApplication, you have access to a whole bunch of instance variables that SimpleApplication provides. You won’t have these in other classes and so you must provide them. This is the source of a whole lot of beginner pain but is really a fundamental thing. It’s as basic as putting on your shoes is compared to climbing a mountain.

and what about making static instance?
something like this:

[java]public class Game extends SimpleApplication {

    private static Game instance = null;

…
public Game() {
super();
instance = this;
}

    public static Game getRoot() {
            return instance;
    }

}
[/java] or is this a bad approach?

@kwando said: This might not be what you wanna hear but it is what most guys here is going to tell you;

You are trying to code a game without a proper understanding of Java and the core concepts of object oriented programming… this is the gates to a world of pain.

You will be better off by spending some time getting up to speed on programming before building a game because you are only going to waste your time fighting issues like this anyways…

I figured out my issue, I needed to extend SimpleApplication to pass needed methods and functions to my other package classes :confused: the methods and objects i needed are from the SimpleApplication class from jme3 (yes Inheritance)

Ill be honest, I have read 4 java books, the Javadoc, but and done practice code from school, and some online, but it just isnt the same as coding a real program.

Everyone has been telling me I need a firmer grasp on it, I just need more experiance actually coding, instead of milling around the books.

sad that i do not know how to read :frowning:

@JohnZamoider said: Everyone has been telling me I need a firmer grasp on it, I just need more experiance actually coding, instead of milling around the books.

Yeah, that’s exactly the point :slight_smile:

Well… coding a game is somewhat more complicated than some other kinds of software, so I can understand the reservations voiced, but I still beg to differ. At least you found a solution to your issue, which is good - it means you have the tenacity and capability to research and implement a solution, and that’s what makes the ability to learn coding, then programming, then designing.
I can’t tell from the solution given whether the solution you found is good. All solutions start with adding code and data to SimpleApplication, the interesting point is what parts of the code are going to see what data. But that’s for a later lesson - right now, you’re learning to code, and you seem to be doing quite nicely there, so I see no real reason to tell you to try something other than game programming.

Like, I can break down a program and understand how the mechanics were made, its the, putting it to paper without having all of the javadoc laid out in front of me lol. My wife would kill me if I took my office walls and made Javadoc wallpaper lmfao(I am sure I am not the only one that has thought of that).

But, you know what they say, no learning like the hard way.

1 Like

It depends, there are sometimes use cases where it is valid, but often it will later break or complicate other stuff. Anyway to decide if it is such a case, one needs to understand the implications and potatial problems & benefits of both solutions.