Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: ScottDoom on Fri 20/01/2006 06:09:46

Title: Idle View Problems (SOLVED)
Post by: ScottDoom on Fri 20/01/2006 06:09:46
{ if (IsGamePaused()==0) cKar.SetIdleView(5,Ã,  0) && cBall.SetIdleView(7, 0) && cAla.SetIdleView(11,3);
Ã,  }


cKar and cBall are animating in idle view. cAla isn't. Why not? It's the exact same line of code. I don't get it. cBall and CAla are exactly identical (code-wise, not graphic-wise, they use different views but set up the same).

???
Title: Re: Whaaaaaat? *pulls hair out*
Post by: Gilbert on Fri 20/01/2006 06:14:41
You should not use the logical && operators here, when you want to execute several lines of stuff:

if (IsGamePaused()==0) {
  cKar.SetIdleView(5,  0);
  cBall.SetIdleView(7, 0);
  cAla.SetIdleView(11,3);
}
Title: Re: Whaaaaaat? *pulls hair out*
Post by: ScottDoom on Fri 20/01/2006 06:19:25
Hmm... Okay, that fixed it. But why couldn't I use the &&? It worked fine for the first two, but went fishy when I added the third. I see that it is more logical to do it in the way you did it though.

Also, would attaching it to the if (isGamePaused()==0) be the best idea? It was the only thing I could think of.
Title: Re: Idle View Problems (SOLVED)
Post by: Gilbert on Fri 20/01/2006 06:43:35
Because && is an operator which is mainly used for conditional programming (e.g. in the executing conditons of if, like (if (a==1&&b==2) blah bla), not for executing commands in a block.

Moreover, since AGS V2.71 lazy evaluation was implemented for && and || operators, say for example in the case of (expressionA && expressionB) expressionB will not be checked (i.e. not "executed") if expressionA was found to be false already.

For functions like Character.SetIdleView(), since the manual doesn't specific what it will return when executed (can be any random value, or even nothing), it's a very bad idea to use them in conditions.
Title: Re: Idle View Problems (SOLVED)
Post by: Khris on Mon 23/01/2006 12:48:59
Code like this goes into the game_start().
Title: Re: Idle View Problems (SOLVED)
Post by: TerranRich on Mon 23/01/2006 17:17:04
AGS uses the basic rules of C programming: separate all commands with semicolons (;) and leave && for use in conditions such as with "if" statements, not commands.