• In a function that includes (Player player, SWGObject Target)

    I want to CreatureObject creature = player.getCreatureObject(); but replace player with target

    I thought I could add the get and set CreatureObject to SWGObject, however it started getting above my pay grade.


  • I'm not 100% certain on what you're asking, but: If you know for certain that target is a CreatureObject, you could do: CreatureObject creature = (CreatureObject) target;

    Perhaps some context as to what you're trying to do would help me understand your situation?


  • CreatureObject creature = (CreatureObject) target <-- That is what I was looking for.

    I'm familiarizing myself with the code, etc... so I added changing HoloColour to the qatool and wanted to be able to apply it to the selected target.

    Thanks for you assistance!

  • Ah, I see. My suggestion should hold, in that case... unless someone was attempt to set the HoloColour of something that isn't a CreatureObject.

    You could run an instanceof check to make sure that target is a CreatureObject, like so:

    1. if(target instanceof CreatureObject) {
    2. // The target is a creature
    3. } else {
    4. // The target is NOT a creature
    5. // Send an error or just return?
    6. }


  • If did use a instanceof incase the player did not have a target, then it would apply to themselves.

    However, I just notice that if I don't have my mouse on the target, then the target is not passed. I had assumed when you clicked on another player or object that became the target.

    I will figure that out tomorrow.

    Thanks again for your help!

  • Yeah, the target is the SWGObject which your cursor is hovering over.


  • What you're looking to do is to do type-casting: Going from one instance type of the object (SWGObject) to another. You need to be careful though, because you cannot cast an object to an instance if it isn't an instance of that object, which is one of the dangers of an implicit typecast. You won't catch it until you actually test the code, the compiler will still compile the code. This is why the instanceof checks as Ziggy mentioned are useful. When we program we always tend to stick to the lowest possible object for that method, that way type casts are not necessary even when passing them as parameters in a method.

    Basic overview of type casting on simple numeric types:
    More explanation:…l/java-object-typecasting