Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Matt Brown on Sat 14/06/2003 21:04:21

Title: Display score on key press...?
Post by: Matt Brown on Sat 14/06/2003 21:04:21
Okay, I know this sort of thing is mentioned in teh manual, but I think I need it explained in a different way...


I want to have my game set so when one presses the "s" key, a message displays their current score out of possible points. I think the built-in GUI varibles doohicky for score would work here, (like, display "@score out of @totalscore, or whatever those are) but if I have to create a global int, and use other varibles, lemme know.

I dont however, know where or what to put for the script for teh whole pressing S part. please enlighten me


thanks guys!
Title: Re:Display score on key press...?
Post by: Jimi on Sat 14/06/2003 21:13:12
er... i think it might be something like....

on_key_press(84) {
   GuiOn(3);
   Wait(180);
   GuiOff(3);
   }


and have a gui with @score out of @totalscore or whatever in it. it will come on, wait for about 5 seconds, then go offf...hopefully.
Title: Re:Display score on key press...?
Post by: Matt Brown on Sat 14/06/2003 21:18:57
hmmmm, not really what I'm looking for.

I'm shooting for when the player presses S, a window pops up, like if the player looked at a hotspot, that said, Blah Points out of Blah Possible.

Jimi, all I think that does is flash the GUI.
Title: Re:Display score on key press...?
Post by: Jimi on Sat 14/06/2003 21:21:15
oh. then...

on_key_press(84) {
   Display("@score out of @totalscore");
   }


I'm pretty sure you can use the @thingy's in stuff other than GUIs.  :-\
Title: Re:Display score on key press...?
Post by: Matt Brown on Sat 14/06/2003 21:23:07
okay, few more questions then..

1. where does this go?
and 2. do I copy that just like it is?

almost got it

thanks
Title: Re:Display score on key press...?
Post by: Jimi on Sat 14/06/2003 21:31:50
wow. Right. I think it would go in the global script. Otherwise you'd have to put it in every room. You could try it like that, but if it has a script error, change it to something like....

if (on_key_press(84)) {
   Display("Blah Blah Blah");
   }


i'm not 100% sure though, since I've never used this before. Good luck!
Title: Re:Display score on key press...?
Post by: Matt Brown on Sat 14/06/2003 21:40:48
okay, I think I might have it...I bet there is a certain place in teh global script where it goes though...hmmmm..

thanks jimi. if anybody can offer more complete answers, I'm all for them
Title: Re:Display score on key press...?
Post by: Matt Brown on Sat 14/06/2003 21:47:47
hey, I set it up so when I press S, word appear...but it looks like @SCORETEXT@ only works in GUIs....waaaa
Title: Re:Display score on key press...?
Post by: Scorpiorus on Sat 14/06/2003 21:55:43
A little correction:

in global's repeatedly:

if (IsKeyPressed(83)) {
Display("Score: %d out of %d", game.score, game.total_score);
}




another way just to modify on_key_press() itself:

function on_key_press(int keycode) {
// called when a key is pressed. keycode holds the key's ASCII code
if (IsGamePaused() == 1) keycode=0;  // game paused
if (keycode==83) Display("Score: %d out of %d", game.score, game.total_score);
//...
//...
//...
}

-Cheers
Title: Re:Display score on key press...?
Post by: Jimi on Sat 14/06/2003 21:58:17
hmm. I was just a little off  :-[. I wasn't sure whether to use IsKeyPressed, because the manuakl said something about it only working with the functions "below"....so... :-[
Title: Re:Display score on key press...?
Post by: Matt Brown on Sat 14/06/2003 21:59:37
thanks. That ought to do it