Terrain - cannot find symbol

Hi,

I’m getting the following error:

Cannot find symbol
Symbol: Variable terrain.

I’m following the instructions here: https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:terrain_editor?s[]=terrain&s[]=editor

I created a scene, added a terrain. Used the editor to add textures then added the code found at the end of the page :

TerrainLodControl lodControl = ((Node)terrain).getControl(TerrainLodControl.class);
if (lodControl != null)
lodControl.setCamera(getCamera());

I then get the error “Cannot find symbol”. I use the code as is and I have tried changing “terrain” to the name of the terrain that I use.

I’m assuming I did something wrong somewhere? Missed out something? But I don’t see what. Anyone with any ideas what I did wrong?

Thanks.

You didn’t call your terrain object “terrain”, but something else.

As I said :

“I use the code as is and I have tried changing “terrain” to the name of the terrain that I use.”

But I still get the same error.

Show the full exception with stack trace for your error.

Not sure how to get a stack trace for this so I have attached a screen shot of what I see:

I’m following the instructiions from this page:

https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:terrain_editor?s[]=terrain&s[]=editor

The code I enter is in the last part of that page.

Thanks for your time.

where do you create the terrain variable?

<cite>@wezrule said:</cite> where do you create the terrain variable?

Now that is the interesting question. I’m following the instructions on the page given above regarding the terrain editor. As the instructions say nothing about creating a terrain varible I have no idea how to do that. I took it as read that the necessary variable was created as part of the creating a terrain as given in the instructions.

Somewhere along the lines something went missing in the instructions. There’s something else outside of the instructions I need to to. But what? Create a terrain variable? Then how? How does it link up to the terrain I created in the terrain editor? Do I need to somehow load the scene? Does that then load the terrain with the terrain variable?

What have I missed? Has anyone actually used the terrain editor to create a terrain? If so, how did you load the terrain and get it working?

You should learn java before you write games with it. This is not intended to be bashing, its just the truth.

As normen said, you will have to brush up on Java a bit more and run through some of the tutorials.

I see you are trying to attach the LOD control to the terrain. You need to find the terrain in the scene first. Terrain is just a mesh attached to the scene node. So to find it, you have to dig down in the scene, getting all the children from the root node, and those children, and their children, testing to see if one of them is a Terrain object
if (spatial instanceof Terrain) {
// yay I got the terrain, now I cast the Spatial to Terrain and I have my terrain variable
}

Before you start all of that though, look at the Node class and its getChild(String name) method. Get familiar with it and how it is finding the spatial recursively.

[java]
/**
* getChild returns the first child found with exactly the
* given name (case sensitive.) This method does a depth first recursive
* search of all descendants of this node, it will return the first spatial
* found with a matching name.
*
* @param name
* the name of the child to retrieve. If null, we’ll return null.
* @return the child if found, or null.
*/
public Spatial getChild(String name) {
if (name == null)
return null;

    for (Spatial child : children.getArray()) {
        if (name.equals(child.getName())) {
            return child;
        } else if(child instanceof Node) {
            Spatial out = ((Node)child).getChild(name);
            if(out != null) {
                return out;
            }
        }
    }
    return null;
}[/java]

<<As normen said, you will have to brush up on Java a bit more >>

I already know Java, been using for many years now. As far as I can see, this is not a Java problem. So, in an attempt to explain this a bit better:

You have a tutorial that explains how to use the terrian editor - so far so good

Your tutorial then provides an example of how to link up the output from the terrain editor into the code. - it fails

Therefore, the tutorial provides insufficient information. - the tutorial is where the problem lies

I hope you follow that.

<<You need to find the terrain in the scene first. Terrain is just a mesh attached to the scene node. So to find it, you have to dig down in the scene, getting all the children from the root node, and those children, and their children, testing to see if one of them is a Terrain object >>

Now, that’s information that should go in the tutorial. Thanks.

If that is the sort of things that needs to be done to go from designing a terrain in the terrain editor to getting it to work in the code then I would suggest you add that to the tutorial with a working example so we can follow it.

Thanks again.

<< You need to find the terrain in the scene first. >>

How about like this:

Spatial terrain = ((Node) myTerrain).getChild(“terrain-<scene name”);

After loading the scene using asset manager to get myTerrain.

How about this?

https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:terrain_editor?&#loading_terrain_into_your_game

Does it make more sense?

It is a wiki, just edit it :slight_smile: