Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Armageddon on Mon 20/08/2012 07:15:10

Title: Timer and Score Bar
Post by: Armageddon on Mon 20/08/2012 07:15:10
Hello again. So I'm making a game that's on a timer, it will probably be an hour or two hours. Once the timer is up the game restarts. I can't find anything in the help guide about how to do a timer or how to have something execute when the timer ends.

Also I have a max score of 100 in the game, instead of using numbers I'd like to use something like a slider, so as you get more points it slide from the left to the right. I'm thinking something about setting the slider to have 0-100 and then having it equal the amount of the score?

Thanks!
Title: Re: Timer and Score Bar
Post by: kconan on Mon 20/08/2012 08:07:40
Lookup "SetTimer" in the help.  To set a timer where 1 is the ID and 5 is the duration in game cycles:
Code (AGS) Select
SetTimer(1, 5);

and to see if it expired:
Code (AGS) Select
IsTimerExpired(1);

It returns a "True" value if the timer has expired.  As for the second part of your question, sorry I haven't worked with slider controls in AGS before.
Title: Re: Timer and Score Bar
Post by: Crimson Wizard on Mon 20/08/2012 08:40:45
Quote from: ArmageddonI can't find anything in the help guide about how to do a timer
Yeah, it is put into "global functions" sections, may be a bit confusing. http://www.adventuregamestudio.co.uk/wiki/?title=Game_/_Global_functions#SetTimer
Anyway, kconan explained how to use it already.


Quote from: ArmageddonI'm thinking something about setting the slider
What about drawing the progress bar using raw drawing instead? That may look much prettier.

One of the ways to do that is to create a DynamicSprite from the sprite you are using for GUI's background (if you aren't create one transparent one with the size of GUI). Or, optionally, you may put button with no on-click handler.
So, you create a DynamicSprite at the game start and assign that new Dynamic Sprite as either the whole GUI or button's background (depending on your choice):
Code (ags) Select

DynamicSprite* glProgressBarSprite; // this MUST be a global pointer, otherwise the sprite is released as soon as function ends

function game_start()
{
   ...
   glProgressBarSprite = DynamicSprite.CreateFromExistingSprite(SPRITE_ID);
   gGUI.BackgroundGraphic = glProgressBarSprite.Graphic;
   // or
   gProgressButton.NormalGraphic = glProgressBarSprite.Graphic;
   ...


Now you basically can draw upon the dynamic sprite anytime you want, and the GUI graphic will change.
Example code:
Code (ags) Select

function OnScoreChanged()
{
   DrawingSurface *ds = sprite.GetDrawingSurface();
   ds.DrawRectangle(0, 0, 1 * game.score  10); // fill rectangle, which width depends on current game's score
   // you may apply more math here, like calculating percent of total score and take maximal progress bar size into consideration
   ds.Release(); // release drawing surface when finished drawing
}

You may draw using basic graphics and/or draw sprites.
Title: Re: Timer and Score Bar
Post by: Armageddon on Mon 20/08/2012 08:44:03
Well it's going to be a radio dial thing, so an actual bar that fills up isn't what I want, and since you can use your own graphics in a GUI Slider it should look good?
Title: Re: Timer and Score Bar
Post by: Crimson Wizard on Mon 20/08/2012 08:47:23
Quote from: Armageddon on Mon 20/08/2012 08:44:03
Well it's going to be a radio dial thing, so an actual bar that fills up isn't what I want, and since you can use your own graphics in a GUI Slider it should look good?
Ah, right, you can have your own graphics for slider too.
I just thought raw drawing is worth to be mentioned.
Title: Re: Timer and Score Bar
Post by: Armageddon on Tue 21/08/2012 00:13:04
Quick question, do you pretty much throw a ton of stuff into repeatedly executed? It seems like it always gets very messy for me.

Also is this right?
Code (ags) Select
    Slider1 = game.score;[/ags]
Title: Re: Timer and Score Bar
Post by: Khris on Tue 21/08/2012 06:27:10
Yes, but what I do is break it down into chunks and put them in their own functions:
Code (ags) Select
function repeatedly_execute() {
  HandleMovement();
  UpdateScreen();
}


Quote from: Armageddon on Tue 21/08/2012 00:13:04Also is this right?
No, Slider1 is a slider and game.score is an int. You need Slider1.Value = game.score;
Title: Re: Timer and Score Bar
Post by: Crimson Wizard on Tue 21/08/2012 09:11:38
Quote from: Khris on Tue 21/08/2012 06:27:10
Yes, but what I do is break it down into chunks and put them in their own functions:
Code (ags) Select
function repeatedly_execute() {
  HandleMovement();
  UpdateScreen();
}

Also, I think I'd mention this: you may break your code into separate modules and make "repeatedly_execute" in every of them (if needed). AGS allows to make "standard" global functions like game_start, repeatedly_execute, on_mouse_click and some others in every module. I think they are called in the same order as scripts are listed in the project trees, e.g. first "repeatedly_execute" from the upper script, then from the second script and so forth.
Title: Re: Timer and Score Bar
Post by: Armageddon on Tue 21/08/2012 21:50:57
One other thing. How do you do default phrases? Like "I can't use that." or "Why would I want a [objectname]" ect.?
Title: Re: Timer and Score Bar
Post by: Khris on Tue 21/08/2012 22:17:44
If you're using the default interface (as in, the various cursor modes trigger the related events), AGS automatically tries to call the function unhandled_event (http://www.adventuregamestudio.co.uk/manual/TextScriptEvents.htm) in the Global script if there's no function linked to an event.

You might want to add additional handling for special cases; basically you check for the situation in on_mouse_click and proceed differently than the usual ProcessClick().

Something I like to do is use Custom properties for individual messages. If you add a String property for each action to objects, you can enter a corresponding line in there ("It's too heavy to lug around.") or leave it empty to give a default phrase.
Title: Re: Timer and Score Bar
Post by: Armageddon on Wed 22/08/2012 08:10:39
Quote from: Khris on Tue 21/08/2012 22:17:44Something I like to do is use Custom properties for individual messages. If you add a String property for each action to objects, you can enter a corresponding line in there ("It's too heavy to lug around.") or leave it empty to give a default phrase.
Could you explain more on how to do that? Sounds very helpful.

Also I have a 9-Verb gui mostly working but I can't figure out how to change the cursor back to Walk when you you click anywhere in the background. Also how do you turn off the greying out of thee gui during a cutscene? I'd like to to just go invisible.
Title: Re: Timer and Score Bar
Post by: Khris on Wed 22/08/2012 09:47:05
What GUIs look like during blocking events is an option in General settings.
And there's a full-fledged 9-verb GUI template that comes with AGS... but if you did reinvent the wheel, check GetLocationType in on_mouse_click and if it's eLocationNothing, set the cursor mode to eModeWalk.

About the Custom properties thing, just add a String property called "open" with a default value of "" to all objects (and hotspots?). Then, while processing an "Open X" click, read the value (Object.GetTextProperty) and if it's something other than "", have the player say the custom phrase, otherwise the default one.
Title: Re: Timer and Score Bar
Post by: Armageddon on Wed 22/08/2012 23:51:16
How do you check what mouse mode is processing?
Title: Re: Timer and Score Bar
Post by: Armageddon on Fri 24/08/2012 06:26:37
Also I have added more mouse modes but hotspots/objects won't show anymore than the two usermodes.
Title: Re: Timer and Score Bar
Post by: Crimson Wizard on Fri 24/08/2012 08:14:53
Quote from: Armageddon on Fri 24/08/2012 06:26:37
Also I have added more mouse modes but hotspots/objects won't show anymore than the two usermodes.
They won't. AGS can't do that (unfortunately).

Quote from: Armageddon on Fri 24/08/2012 06:26:37
How do you check what mouse mode is processing?
By reading manual :P
http://www.adventuregamestudio.co.uk/wiki/?title=Mouse_functions_and_properties#Mouse.Mode
Title: Re: Timer and Score Bar
Post by: Khris on Fri 24/08/2012 09:48:35
Quote from: Armageddon on Fri 24/08/2012 06:26:37
Also I have added more mouse modes but hotspots/objects won't show anymore than the two usermodes.

Use the "any click on" event and check for mouse.Mode in there.
But again, there's a perfectly good 9-verb template that comes with AGS.