Get View Frame Question

Started by theatrx, Thu 09/08/2007 17:27:12

Previous topic - Next topic

theatrx

I'm not sure if this is possible or not but it seems like it should be but I'm coding it wrong.

While animating the gui button "MICHAELHEALTH"  when it gets to the second loop, 15th frame I would like to display a message.

So far I have

if (ViewFrame *frame = Game.GetViewFrame(MICHAELHEALTH) == 2, 15);
Display("I'm getting really thirsty and hungry.");

Can this be an if statement?
Life is a banquet and most poor sonsofbitches are starving to death

Khris

A Viewframe won't change while something is animating.
Game.GetViewFrame returns the sprite slot that was set in the editor.

Obviously you can't compare something to "2, 15", much less a command.

You'll want:
Code: ags
  ViewFrame*vf=Game.GetViewFrame(MICHAELHELATH, 2, 15);
  if (vf.Graphic==MichaelHealth.Graphic) {
    Display("I'm getting really thirsty and hungry.");
  }

where "MichaelHealth" is the script name of the button.

theatrx

Okay... it now says:

Cannot assign initial value to global pointer

I also tried:

if (Game.GetFrameCountForLoop(19, 1)) == 15   {

Display ("I'm getting thirsty and hungry.");
}

19 being the view number for MichaelHealth

I think this would be cool if it works.  Thanks for the help so far.
Life is a banquet and most poor sonsofbitches are starving to death

Khris

Quote from: manualReturns the number of frames in the specified loop of the specified view.
Why do you try random functions instead of correcting the errors you get?
Where did you put the code?
You did put it in the repeatedly_execute function, right?

Because the error you get suggests you didn't.

If done right, this will work. Although it's a bit weird to call a blocking Display command in the middle of an animation.

Could you elaborate on what you're trying to achive?
It looks like you want to create some kind of health bar. I don't think animating the button is the right way to do that.

theatrx

Sorry about the newbness but I am trying to create a health bar.

The bar itself works perfectly... the display blocking command doesn't really matter that there is a brief pause since time is still ticking.

I was just hoping that if an individual frame is recognized (each frame plays for 5 seconds) that something else could happen at three intervals...Thirst, hunger and death.

I've read the threads on the health bar issue but none of them seem like they would work as seemlessly as this one.  I'm sure you know how it is when you get something in your head and you can't change it.  Again, thank you for your help.
Life is a banquet and most poor sonsofbitches are starving to death

Khris

I'd do it using a timer.

Code: ags
// inside game_start:
  SetTimer(1, 1);  // start timer loop



int health=100;

function repeatedly_execute() {

  if (IsTimerExpired(1)) {
    health--;  // decrease health by one
    MichaelHealthBtn.Graphic=health/5+20;   // sprite slots 20-40
    if (health==40) player.Say("I'm thirsty.");
    if (health==20) player.Say("I'm hungry now, too.");
    if (health==0) {
      player.Say("Aarg.");
      player.ChangeRoom(DIE_SCREEN);
      return;
    }
    SetTimer(1, GetGameSpeed()*5); // decrease health every 5 seconds
  }
}

monkey0506

A better way than using a bunch of sprites would be to make the Button just the inner part of the health bar (assuming you have some type of outline around it; if you don't just make the Button for the full size of the health bar) and set its Graphic to a sprite containing the full health bar. You can then use the Button's ClipImage property (set to true) to make AGS clip the image down to the Width of the Button, then use the Width to control the health.

SMF spam blocked by CleanTalk