Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: rickious on Tue 01/10/2013 22:04:12

Title: derpy movement after ChangeView [SOLVED]
Post by: rickious on Tue 01/10/2013 22:04:12
So, My character has boots in his inventory, you click the boots, then click the boots on the character...

Code (ags) Select
function cEgo_UseInv()
{
  if(player.ActiveInventory == iCleanBoots)
    player.LoseInventory(iCleanBoots);
    cEgo.ChangeView(3);
}


View changes to '3:BOOTS' but its all muddled up.  I have checked the view and its identical to the bootless view in terms of animation, everything is in the right place.  I have ran the preview and everything runs smooth.

I have tried changing (3) to (BOOTS) and it does the same, really dont know what else to try.
Title: Re: derpy movement after ChangeView
Post by: monkey0506 on Tue 01/10/2013 22:31:34
It looks like you're probably missing some braces, but it sounds like the issue is the character movement? What exactly is the problem?
Title: Re: derpy movement after ChangeView
Post by: rickious on Tue 01/10/2013 23:14:08
Its totally mixed up as to which frames to play.  For example, all the standing frames are using mid-walk images.  And I have quadrouple checked all the first images in the loops are standing.  When walking away, he turns left and right lol.

Ill try making a new test view now and change to that instead.
Title: Re: derpy movement after ChangeView
Post by: rickious on Tue 01/10/2013 23:35:40
I set the boots view as 'normal' view for the character and its fine.  So its only the ChangeView that isnt loving things.

So, is there more to ChangeView?  or am I using the wrong script to permanently change the Normal view of a character?
Title: Re: derpy movement after ChangeView
Post by: selmiak on Wed 02/10/2013 00:05:28
as monkey said, you are missing some braces, did you add them already?
Code (ags) Select
function cEgo_UseInv()
{
  if(player.ActiveInventory == iCleanBoots) {
      player.LoseInventory(iCleanBoots);
      cEgo.ChangeView(3);
  }
}

Title: Re: derpy movement after ChangeView
Post by: monkey0506 on Wed 02/10/2013 00:37:05
All ChangeView does is permanently change the "Normal" view (e.g., the view that is restored when calling UnlockView after an animation). It shouldn't affect the way animation frames are displayed, nor should it affect their order. Could you confirm what AGS version you're using? Also, try doing a "Rebuild all" and see if it makes any difference.
Title: Re: derpy movement after ChangeView
Post by: rickious on Wed 02/10/2013 07:38:29
Sorted, what was wrong was I was loading a save point just prior to picking the boots up, but after fulfilling the prerequisits to be able to put them on.  I had changed all the sprites between making the save and re-loading to test.  So it was looking for sprite numbers thar were different.

So it was a false alarm.

My scripting works fine without the extra pair of brackets, presumably because there is no 'else'.  I think 'if' might not be the command to use in this case, but its working well.  But if you feel there is a tidier way to do it, please let me know.  The script I posted is the full script for putting the boots on, I select the boots, use them on the chartacter and it changes to the view with the boots.

Title: Re: derpy movement after ChangeView [SOLVED]
Post by: monkey0506 on Wed 02/10/2013 08:25:46
Glad to hear it's working, but... I don't think you understand what the braces are for.

It's not a matter of "tidy" programming, it's a matter of logic.

The function cEgo_Useinv will be called any time the player uses any inventory on cEgo. So whether the player has used the key card, the red herring, or the boots, it's going to be running this function, and the way you have it now, it's going to change the player's view. Obviously changing the player into the boots when he doesn't have them in his inventory and has used a different item doesn't make any sense at all. That's what the braces are for.

How you have it now:

Code (ags) Select
function cEgo_UseInv()
{
  if(player.ActiveInventory == iCleanBoots)
      player.LoseInventory(iCleanBoots); // without the braces, only this line is run conditionally
      cEgo.ChangeView(3); // this is run EVERY time, REGARDLESS of what item was used
}


The logically correct code:

Code (ags) Select
function cEgo_UseInv()
{
  if(player.ActiveInventory == iCleanBoots)
  { // the braces after the IF statement mean that you want to do ALL of these things conditionally
      player.LoseInventory(iCleanBoots);
      cEgo.ChangeView(3); // CORRECT: view is only changed if using the boots
  }
}


These two code snippets do very different things. The braces make a big difference.
Title: Re: derpy movement after ChangeView [SOLVED]
Post by: rickious on Wed 02/10/2013 11:51:01
Ah. cheers for the explanation. It explains another weird thing that was doing exactly that, (any item interaction completing the puzzle/task)

Thanks Monkey :)
Title: Re: derpy movement after ChangeView [SOLVED]
Post by: monkey0506 on Wed 02/10/2013 20:48:03
Just remember what the braces are for: grouping things together. Functions require braces, but they are optional for conditionals (if, else if, else) and loops (while). Without them, only the very next statement is applied to the conditional or loop. If you have more than one statement, you'll need braces. Until you're more familiar with it, you can keep yourself in the clear by always using braces for conditionals and loops.
Title: Re: derpy movement after ChangeView [SOLVED]
Post by: rickious on Wed 02/10/2013 21:21:14
Thanks again.