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?)?
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);
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. ???
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
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.
Ah, sorry, I've never tested it.
Just replace the line with:
gl++;
update_time(gl);
Well your problem is solved?
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!
You're welcome :)