ArrayList of controlled spatials?

In the jMonkeyEngine 3.0 Beginner’s Guide, page 84 - 86 has the description of what it wants the reader to do at the end of Chapter 3 for the tutorial game.

It says “The constructor takes the GamePlayAppState object instance as an argument because the towers need access to the list of creeps and the beam_node object.” It then a few lines down says “It iterates over the ArrayList of creep objects that it gets from the GamePlayAppState objcect…”

The problem is that the book does not describe where the ArrayList comes from, and how I am supposed to access it. None of the documentation I have read on the AppState objects indicate that they have any sort of automated arrays, but the tutorial is worded as to indicate that such a thing exists and it has not instructed me on how to create it.

I have figured out how to move forward with a workaround, but I am not sure that the way I am doing it is the right way or not.

Thanks for any comments!

Ok, as I was reading through other people’s questions, I found one that was different but about the same page or two of the text.

Someone pointed them to this link: https://code.google.com/p/jmonkeyengine/source/browse/#svn%2FBookSamples%2Fsrc%2Fmygame

It is basically the “Official” version of the Tower Defense game, and it answers a lot of questions.

Overall, the book is still very much worth reading so far, even if there are a few places where I am like “Why didn’t they just say that to begin with?”

An ArrayList is a simple object that exists in the Java core, you can make one at any time. The book can’t really explain everything about Java programming so if something seems new to you maybe check the web to see if its a more basic thing.

The problem I was running into was not a basic Java problem. It was a confusing spec problem.

The page was worded as if there was a built in function doing what it wanted (there was not). What had to be done depended on features of Node, and NOT features of an AppState. The spec said we needed the AppState object to get the list that IT provided.

Looking at the Documentation, I was able to find that there is a getChildren() method on Node (not AbstractAppState), but spent another day or two searching for the “right” way to do it, because I was sure that the book I had spent fifty dollars on would not send me on a wild goose chase.

All in all though, the book is still awesome. :stuck_out_tongue: It just has a few quirks that need ironing out in future editions. I am at the end of Chapter 3, and have only encountered two issues that could bee seen as “boneheaded mistakes,” and as tech books go that is a pretty good record so far. :slight_smile:

The point of the text you quoted is that you can access an AppState (and anything you coded into it) quite easily and that you should thus should put central code into AppStates. Its not so much about what the code in an AppState can do, which is about anything you can imagine. These questions on how to connect code in Controls, the Application and AppStates come up quite often here and I guess somebody wondering about these things would read an answer to these questions instead of attributing the features of the example to AppStates in general. But as you say, technical concepts are sometimes hard to put into words in a sensible sequence and form.

I think that jMonkeyEngine is very well designed. :slight_smile:

Overall, what I have read of the book is great as well.

There was just some confusion in what it was trying to get across.

Interesting bit is that while I was trying to track down what they meant, I ended up doing it pretty much the same way just in a different place. :slight_smile: The idea of using a Node as an array is pretty cool. :slight_smile: