Idle View Problems (SOLVED)

Started by ScottDoom, Fri 20/01/2006 06:09:46

Previous topic - Next topic

ScottDoom

Code: ags
{ 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).

???

Gilbert

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);
}

ScottDoom

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.

Gilbert

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.

Khris

Code like this goes into the game_start().

TerranRich

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.
Status: Trying to come up with some ideas...

SMF spam blocked by CleanTalk