Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Bobsy on Sun 20/06/2010 22:13:19

Title: Instant movement to coords / object.visible = false; [SOLVED]
Post by: Bobsy on Sun 20/06/2010 22:13:19
Problem 1:
When the player interacts with an object I need him to shift position slightly so that the animation lines up properly. I can't for the life of me find the right command to make this shift instant. I don't want him to walk or drift sideways - I just need him to move to new coords in an instant. The closest command I could find is player.changeroom but that gives a great big room changing transition fade in-out.

Problem 2:
As part of the same script, the object itself is supposed to disappear in the same instance the player animation starts. However, for some reason it does no such thing. I suspect it may be due to the fact that the command to make it invisible is nested within an if condition to determine if it's visible in the first place (see below). Otherwise... huh?


function hPot_UseInv()
{
 if (player.ActiveInventory == iWhisk)
 {
   player.Walk(224, 208, eBlock);
   player.FaceObject(oSpaghetti);
   if (oSpaghetti.Visible == true)
   {
     oSpaghetti.Visible = false;
     player.Move(19, 208, eBlock);
     player.Animate(12, 5, eOnce, eBlock);
     player.AddInventory(iSpaghetti);
   }
 }
 else
 {
   player.Walk(224, 208, eBlock);
   player.FaceObject(oSpaghetti);
   cNarr.Say("That item was distinctly unsuited to extracating the spaghetti from the pot.");
 }
}
Title: Re: Instant movement to coords / object.visible = false;
Post by: Matti on Sun 20/06/2010 22:32:48
Regarding the first problem: Simply set the character's coordinates.

player.x =
player.y =

I don't know why the object doesn't disappear though.
Title: Re: Instant movement to coords / object.visible = false;
Post by: Bobsy on Sun 20/06/2010 22:42:46
Okay, updated code, with the changes suggested by Mr Matti, and also to add a missing else statement for using iWhisk on the object when invisible. Of course, I still can't seem to make it invisible...


function hPot_UseInv()
{
 if (player.ActiveInventory == iWhisk)
 {
   player.Walk(224, 208, eBlock);
   player.FaceObject(oSpaghetti);
   if (oSpaghetti.Visible == true)
   {
     oSpaghetti.Visible = false;
     player.x = 219;
     player.Animate(12, 5, eOnce, eBlock);
     player.AddInventory(iSpaghetti);
   }
   else
   {
     cNarr.Say("I'd already dredged out the rubbery mass of spaghetti. There was nothing more I could do.");
   }
 }
 else
 {
   player.Walk(224, 208, eBlock);
   player.FaceObject(oSpaghetti);
   cNarr.Say("That item was distinctly unsuited to extracating the spaghetti from the pot.");
 }
}


Could it be because I've nested an if inside another if? Or because I'm setting it invisible within an if that's dependent on it BEING visible in the first place?
Title: Re: Instant movement to coords / object.visible = false;
Post by: Khris on Mon 21/06/2010 00:24:16
Are the other commands inside the block executed? I.e. does the player animate and does iSpaghetti appear in their inventory?
Title: Re: Instant movement to coords / object.visible = false;
Post by: Bobsy on Mon 21/06/2010 07:33:43
Quote from: Khris on Mon 21/06/2010 00:24:16
Are the other commands inside the block executed? I.e. does the player animate and does iSpaghetti appear in their inventory?

Yes, everything else executes without a hitch.

Last night I tried moving the lines

      oSpaghetti.Visible = false;
      player.x = 219;
      player.Animate(12, 5, eOnce, eBlock);
      player.AddInventory(iSpaghetti);

To a seperate function, and have that activate in its place, but no joy.
Title: Re: Instant movement to coords / object.visible = false;
Post by: Bobsy on Mon 21/06/2010 22:52:36
Well, problem has been solved. And of course it was a simple oversight on my part rather than anything sinister happening within the bowels of the script.

See, above oSpaghetti is anothe object, oSteam. Originally the animation for oSteam incorporated the spaghetti into it as well, before I split the two up to make them more manageable.

I think you can see where this is going.

So yeah, the old animation was in place, and while oSpaghetti was turning invisible as planned, you couldn't tell because its sinister doppelganger was hiding behind it all along. Lesson learned: I'm the idiot, not the game. Sigh!