Issue: If Statement to Define what Loop to play in LOCKEDVIEW? [SOLVED]

Started by PaddyF, Sun 05/05/2019 14:20:16

Previous topic - Next topic

PaddyF

Hello,

Apologies first of all as I am very new to coding.

I have scripted some code to provide some basic animation during dialogue sequences.

This code is either part of a interact function or dialog.

The animation in question uses view 11, which has two loops.

Loop 0 is the animation to the right.

Loop 1 is the animation to the left

( I have not tried to call Loop 1 up within the code yet.)

Code: ags


 //Show Badge Animation
            cChar1.LockView(11);
            cChar1.Animate(0,4,eOnce);
            Wait(20);
            cChar1.UnlockView();
        cProstitute.Say("Nice to meet you Detective Louie Thompson.");


My objective is for the Char1 to animate loop 0

IF: The NPC is right of Char1

And therefore for Char1 to animate loop 1

IF: The NPC is left of Char1.

The game I am working on only has left/right views if that is relevant. Meaning it is a flat 2d Point and Click adventure game.

Any and all help is greatly appreciated, I've tried to find a relevant tutorial for this but I don't quite understand what if/else statements to use or if I need a Global Variable.

Again i'm new to coding.

Thanks for any help or feedback.

Khris

Use
Code: ags
  cChar.Animate((cProstitute.x > cChar1.x) * 1, 4, eOnce);


(the comparison will evaluate to a boolean value, true or false, which is then cast to 1 or 0 because of the multiplication)

More readable way:
Code: ags
  if (cProstitute.x > cChar1.x) cChar.Animate(1, 4, eOnce);
  else cChar.Animate(0, 4, eOnce);

PaddyF

Resolved thank you!

However just to point out initially with your suggestion:

when cChar1 interacts with cProstitute from the right side of the screen, the animation is performed to the right (loop 0), when it should be facing left (loop 1)

when cChar1 interacts with cProstitute from the left the animation is performed to the left (loop 1)

Code: ags


//Show Badge Animation
          cChar1.LockView(11);
            if (cProstitute.x > cChar1.x) cChar1.Animate(1, 4, eOnce);
  else cChar1.Animate(0, 4, eOnce);
                  cChar1.UnlockView();
                    cChar1.FaceCharacter(cProstitute);
                      cProstitute.Say("Nice to meet you Detective Louie Thompson.");


The fully resolved code is:

Code: ags

//Show Badge Animation
          cChar1.LockView(11);
            if (cProstitute.x > cChar1.x) cChar1.Animate(0, 4, eOnce);
  else cChar1.Animate(1, 4, eOnce);
                  cChar1.UnlockView();
                    cChar1.FaceCharacter(cProstitute);
                      cProstitute.Say("Nice to meet you Detective Louie Thompson.");
 


Thank you very much!

SMF spam blocked by CleanTalk