Click animating button and checking if button animating or not..

Started by Slasher, Sun 04/05/2014 17:03:08

Previous topic - Next topic

Slasher

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

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



monkey0506

Quote from: slasher on Sun 04/05/2014 17:03:08
Code: ags
if  (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.

Slasher


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


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
if  (animating==true))
ChurchHelp =1;  
 


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

cheers


Intense Degree

Given how you have put it in your example, could you not just bypass the animation bool and do this?

Room Load
Code: ags


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


Slasher

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...

monkey0506

Glad you got it working, but I would just like to say that under no circumstances should anyone ever have:

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


That is what else means.

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

Slasher

Hi Monkey,

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

cheers

monkey0506

That's what comments are for. Keep in mind that block comments can appear in-line:

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

SMF spam blocked by CleanTalk