Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: FrancoFranchi on Fri 20/04/2007 09:42:36

Title: Fast Forward & Rewind Button Controls (SOLVED)
Post by: FrancoFranchi on Fri 20/04/2007 09:42:36
Hi - One part of my game I'm hoping to implement, despite being a bit difficult for me to figure out how to script, is a control panel of a security camera.  The goal is for the player to skip ahead to a precise frame to find a clue (every other frame would display camera static).

From what I understand, it should be possible to create a variable, two buttons to increase/decrease it and a label to display the - however, I'm guessing that would only create a regular decimal number instead of a time.  Is there any way to get around this (manipulating SetTimer?)?
Title: Re: Fast Forward & Rewind Button Controls
Post by: Khris on Fri 20/04/2007 11:08:09
So you want a display like mm:ss?
Just calculate it from the variable.

Say you are using a variable gl counting the game loops, so 40 loops = 1 second.

int s=gl/40;
int m=s/60;
s=s%60;
lblTimer.Text=String.Format("%02d:%02d", m, s);
Title: Re: Fast Forward & Rewind Button Controls
Post by: FrancoFranchi on Fri 20/04/2007 13:42:22
Thanks for the hints but I'm still getting something wrong.  I've tried setting gl +=1 and gl -=1 for the FF and Rewind buttons respectively and there it is causing no change to the label.  I can only make 00:00 appear whenever I click on either button. ???
Title: Re: Fast Forward & Rewind Button Controls
Post by: Khris on Fri 20/04/2007 14:50:42
You have to put declaration lines outside any function, otherwise the variable will be initialised to 0 every time.

int gl;  // declaration outside any function

function update_time(int x) {
  int s=x/40;
  int m=s/60;
  s=s%60;
  lblTimer.Text=String.Format("%02d:%02d", m, s);
}

#sectionstart
function ff_onClick(GUIControl*control, MouseButton button) {
  update_time(gl++);
}
#sectionend

// same for rewind
Title: Re: Fast Forward & Rewind Button Controls
Post by: FrancoFranchi on Fri 20/04/2007 15:23:39
That makes sense - thanks :)  Following the code you provided, I've switched to a simpler GUI interface (instead of a room with hotspots approach I was using before) so everything can be dealt with in the global script.

However, I keep getting "Parse Error in expr near gl" when I try to call the update_time(gl++) or update_time(gl--) functions.  It seems to at least recognise that the variable exists but isn't capable of performing the function on it - and I can't figure out any way of manipulating it to work.
Title: Re: Fast Forward & Rewind Button Controls
Post by: Khris on Fri 20/04/2007 16:02:39
Ah, sorry, I've never tested it.
Just replace the line with:

  gl++;
  update_time(gl);
Title: Re: Fast Forward & Rewind Button Controls
Post by: Dualnames on Fri 20/04/2007 17:36:01

Well your problem is solved?
Title: Re: Fast Forward & Rewind Button Controls
Post by: FrancoFranchi on Fri 20/04/2007 18:54:09
Hurrah - this has helped me get this part of the game finished :D

Thanks Khris - your name will be in the 'With Thanks To...' section of my game's manual!
Title: Re: Fast Forward & Rewind Button Controls (SOLVED)
Post by: Khris on Fri 20/04/2007 19:06:09
You're welcome :)