i am wondering...

I am using vb.NET part of VS.NET, and no matter how many times i check to see if targetanimal is nothing ( targetanimal being animalstate of the current target ) i always seem to get OrganismNotVisibleException, and my creature ends up attacking nothing or eating nothing until it dies.

anyone know how i can check if the org is visible ( reliably ) and also i seem to find that i get out of range exception too, even though i use withineatingrange(targetanimal) etc... i have had to change to distanceto(taretanimal) <= 10 in order to make it more reliable,


thanks in advance


Answer this question

i am wondering...

  • Bác Ba Phi

    Dead animals and plants have no camouflage. You must refresh your target very often to check if it is still there. I'm giving you some code in C#, try to put it in your LoadEvent. I'm sure you'll be able to translate it into VB.NET:

    target = (AnimalState) LookFor(target); //Try using this in your LoadEvent

    target will remain your target's AnimalState if it's visible (dead or alive). If doing that doesn't solve your problem try improving a little more your AttackCompletedEvent like this:

    target = (AnimalState) LookFor(target); //Translate to VB.NET, place it here, just to be sure
    if(!target.IsAlive) //if target is dead
      if(WithinEatingRange(target)) //if target is within eating range
        BeginEating(target);
      else
        //move to dead target for eating
    else//target is alive
      //since you just attacked in this turn, you must wait for the next turn to attack again
      //here you may want to move toward your target in case he is escaping
      //be sure to check you are WithinAttackingRange(target) before you attempt to attack
    end if

    I hope this helps. If not, please let us know to help you a little more.

  • Ivan Ivanyuk

    You can use a Try...Catch statement to find if you get an error. If an exception occurs, it will run code Catch. A bit unorthodox, but it works. Here is a sample using pseudocode:

    Try
    FindAnimal(organism)
    organismVisilbe=True
    Catch exc As Exception
    organismVisible=False
    End Try

    I'm a beginner, so i'm not EXACTLY sure if it will work. Good luck!

  • Rick Schummer

    I'm using terrarium 1.0.21.281 and IsAlive works perfectly for me (ie my creatures). However, if it doesn't work for some people, you should use EnergyState.Dead, as pointed out by dkocur, to make sure your creature will work as it should in every terrarium.
  • Dubloth

    Sneakypete, don't use IsAlive.  It doesn't work.  Instead, look at the animal's energy state.  If it's EnergyState.Dead, then start eating.  :o)
  • Lam Chan

    well, after a little work it still does not work, i find my creature attacking, an animal, and even when it rotted away it still attackes, even though in the attackcompleted event i haf, 

    if not target.Isalive then

    see if you can eat it ( ie is it visible ) if not findnewtarget

    else

    attack

    end if


  • Hawk390

    Sometimes you have an actual AnimalState assigned to your targetanimal variable (therefore it is not null) but somehow the creature dissapeared. You can try using LookFor(targetanimal) in your LoadEvent. LookFor returns OrganismState so you must then cast it to AnimalState and assign it to targetanimal. Your variable targetanimal will become null if the creature is no longer visible by your creature (maybe because of camouflage).

    hope this helps.

  • Vivek Dalvi-MSFT

    ah yes camo, i forgot about that...

  • i am wondering...