SOLVED:Moving object will not animate when moving.. script error undefined taken

Started by barefoot, Fri 25/02/2011 11:05:35

Previous topic - Next topic

barefoot

Hi

UPDATE: I've searched around again and used this and it works..

Code: ags

function room_RepExec()
{
  if (obird.Visible)
  obird.Animate(0, 5, eRepeat, eNoBlock);
}



For some reason my object (obird) will not animate as it flys off, i get an undefind error that says that obird is undefined taken.  I know that with characters the move command slides rather then walks...  what would be best to use?

Its this bit  
Code: ags
obird.Animate(0, 5, eRepeat, eNoBlock);
 
that is causing the problem.
It runs ok elsewhere in the scene like going on to  a region makes it animate.

Code: ags

function cwizard_UseInv()
   
{    
 if (HasPlayerBeenInRoom(3)&& player.ActiveInventory==ihorn) {
  cwizard.LoseInventory(ihorn);
  player.FaceObject(object[3]);
  Display("You take out your magic Horn and give along blast. The wailing banshee sound is unbelievably wailing so you close your ears and it scares the bird and it fly's off.");
  aBird.Play();
  obird.Animate(0, 5, eRepeat, eNoBlock);
  object[3].Move(20, 13, 1, eBlock, eAnywhere);
  object[3].Visible = false;  
  aBird.Stop();
  cwizard.Say("Good job I brought my horn along!");
  cwizard.Say("I need to get that prism!");
}

 else Display("I can't use that!");
}


All help appreciated

cheers

barefoot



I May Not Be Perfect but I Have A Big Heart ..

monkey0506

Okay, you've marked this thread as solved, but I see a couple problems here. In your "solution" code, you are constantly telling obird to animate. Even if you have so few frames that this doesn't actually cause noticeable issues in the animation, it's ridiculously inefficient to do this. I'd recommend changing that just a bit:

Code: ags
function room_RepExec()
{
  if ((obird.Visible) && (!obird.Animating)) obird.Animate(0, 5, eRepeat, eNoBlock);
}


By checking the object's Animating property you make sure that you're only telling it to animate if it isn't already animating.

Another problem I see is that you give no indication that you understand why you were getting the error, so I want to explain that to you.

Objects are room-specific items. They do not exist outside of the room which they belong to. Because of this you could have an Object named obird in every room in your game and there would be no conflict or errors because each object would only exist in its own room.

However, since the objects do not exist outside their rooms, you should also be aware that the objects script names (like obird) do not exist outside of the room either. The room script is the only script file directly tied to each individual room, so within the room script you can use object script names like obird, because the object and the script both belong to the same room. Other script files do not belong to the room though, so they can't understand what you're trying to reference when you type an object's name outside of the room script. You can access the objects using their ID number via the object array (like object[2]), as that is a global array of Object*s that are updated when a new room is loaded.

So the reason it was throwing an error that obird was an undefined token is simply that outside of the room script, obird did not exist.

barefoot

Hi Monkey

that was some information there.. i have added it to notepad for reference.. and thank you. I learnt a few bits there, understanding wise...

cheers again

barefoot

I May Not Be Perfect but I Have A Big Heart ..

SMF spam blocked by CleanTalk