Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Sun 04/05/2014 17:03:08

Title: Click animating button and checking if button animating or not..
Post by: Slasher on Sun 04/05/2014 17:03:08
Hi,

I'm having a bit of brain bother at the moment.

I am looking for a way to capture (mouse clicking) on an animating button.

The player enters a room, a button is animating (flashing).

If the player clicks on the button whilst it is animating he gets ChurchHelp =1 else if the button is not animating he gets ChurchHelp =0. On both occasions he goes to Room 17 where Church function carries out the ChurchHelp check and responds accordingly and then returns to room and the animating button stops and ChurchHelp=0.

This animating button animates in further rooms until it is clicked.

There is not a check for if Button animating afaik.

What I have so far:

On Room on Load:

Code (ags) Select

if(HasPlayerBeenInRoom(17)){ // Church Room already visited
Button74.NormalGraphic=710; // Church button normalgraphic
ChurchHelp =0;
}
else if(!HasPlayerBeenInRoom(17)){ // Church Room not yet visited
Button74.Animate(17, 1, 4, eRepeat);   // Church button flashing

if  (Button74.Animate(17, 1, 4, eRepeat))
ChurchHelp =1;   


Animating Sprites, in order: 710  2997 710  2997

Can you assist me please..

cheers


Title: Re: Click animating button and checking if button animating or not..
Post by: monkey0506 on Sun 04/05/2014 18:24:59
Quote from: slasher on Sun 04/05/2014 17:03:08if  (Button74.Animate(17, 1, 4, eRepeat))

Button.Animate does not return a value, it is the command to start the button animating. So, obviously, this won't work.

As you pointed out, there's not any type of Button.Animating property to let you know if the button is currently animating. The best option presently is just to create a separate bool variable to track it yourself. When you call Button.Animate, set the bool to true. When you stop the animation (e.g., change the NormalGraphic), set the bool to false. Then you can check if the button is animating by checking your variable.
Title: Re: Click animating button and checking if button animating or not..
Post by: Slasher on Sun 04/05/2014 18:49:58

EDIT: I copied the button normal sprite and pasted as new sprite number and used that in the animation, seems to work so far...

Hi Monkey,

I have added a Global boolean 'animating' (set to false) and set it to true if button is animating. Then in rep exec added if boolean animating is true Churchhelp=1

Room Load
Code (ags) Select


if(HasPlayerBeenInRoom(17)){ // Church Room already visited
Button74.NormalGraphic=710; // Church button normalgraphic

}
else if(!HasPlayerBeenInRoom(17)){ // Church Room not yet visited
Button74.Animate(17, 1, 4, eRepeat);
animating=true;   //



Rep exec
Code (ags) Select
if  (animating==true))
ChurchHelp =1; 


should this work as it seems to be returning ChurchHelp =0?

cheers

Title: Re: Click animating button and checking if button animating or not..
Post by: Intense Degree on Tue 06/05/2014 16:08:44
Given how you have put it in your example, could you not just bypass the animation bool and do this?

Room Load
Code (ags) Select


if(HasPlayerBeenInRoom(17)){ // Church Room already visited
  Button74.NormalGraphic=710; // Church button normalgraphic
  ChurchHelp = 0;
}
else if(!HasPlayerBeenInRoom(17)){ // Church Room not yet visited
  Button74.Animate(17, 1, 4, eRepeat);
  ChurchHelp = 1;
}

Title: Re: Click animating button and checking if button animating or not..
Post by: Slasher on Tue 06/05/2014 17:54:16
Hi Intense Degree,

Whilst I started with that code it is in fact more complicated with additional factors. Anyhow, I seem to have solved the issue, at least for now.

cheers anyway...
Title: Re: Click animating button and checking if button animating or not..
Post by: monkey0506 on Tue 06/05/2014 18:05:38
Glad you got it working, but I would just like to say that under no circumstances should anyone ever have:

Code (ags) Select
if (condition) { }
else if (!condition) { }


That is what else means.

Code (ags) Select
if (condition) { }
else { }


Is sufficient if all you are doing is checking the inverse of the original condition. You should only have else if when you are checking multiple (more than two) unique possibilities, such as the results of Random(10) or the current mouse.Mode.
Title: Re: Click animating button and checking if button animating or not..
Post by: Slasher on Tue 06/05/2014 18:08:13
Hi Monkey,

I totally agree. I only added it so i could see the whole thing better. Sounds silly but true ;)

cheers
Title: Re: Click animating button and checking if button animating or not..
Post by: monkey0506 on Tue 06/05/2014 23:00:53
That's what comments are for. Keep in mind that block comments can appear in-line:

Code (ags) Select
if (condition) { }
else /* if (!condition) */ { }