Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MrAbu on Sat 05/08/2017 02:05:25

Title: repeatedly execute issue, is there a better way?
Post by: MrAbu on Sat 05/08/2017 02:05:25
So what I wanted to do was set up a dialog when the player got a certain score, I thought the best way to do this was to make a function that repeatedly checks to see if the player reached the score. However, when the score is reached it only does the first part (the player.Say part) and then keeps repeating that one part. How do I make it do both parts? Was the repeatedly execute function the wrong way to go?

Code (ags) Select

function repeatedly_execute()
{
if (act1score == 3){
player.Say("I should get ready to go.");
dendact1.Start();
}
}
Title: Re: repeatedly execute issue, is there a better way?
Post by: Kara Jo Kalinowski on Sat 05/08/2017 02:41:00
The problem you are having is that after that if statement resolves, act1score is still 3, so setting it to 4 inside the if statement will fix your problem. There are also other ways you could do it if that's a problem, but repeatedly_execute checks every game loop even after your if statement resolves.
Title: Re: repeatedly execute issue, is there a better way?
Post by: Crimson Wizard on Sat 05/08/2017 03:08:10
Game.DoOnceOnly function is for making sure something happens just once.

For example:
Code (ags) Select

// this will happen only if act1score is 3, and "Act1Score3" tag was never checked before
if (act1score == 3 && Game.DoOnceOnly("Act1Score3"))
Title: Re: repeatedly execute issue, is there a better way?
Post by: MrAbu on Sat 05/08/2017 03:16:54
thanks! the Morgan's way worked and fixed the problem but the DoOnceOnly method did too, thanks both of you!
Title: Re: repeatedly execute issue, is there a better way?
Post by: Khris on Sat 05/08/2017 17:08:21
An even better solution is to simply check right after changing the score.
  // something happened
  act1score++;
  CheckGetReady();


Edit: one can improve on that, btw.:
function ScoreUp(int act) {
  my_score[act]++;
  // special stuff
  if (act == 1 && my_score[1] == 3) {
    player.Say("I should get ready to go.");
    dendact1.Start();
  }
}


Now one simply calls ScoreUp(1);
Title: Re: repeatedly execute issue, is there a better way?
Post by: Crimson Wizard on Sat 05/08/2017 17:29:21
Quote from: Khris on Sat 05/08/2017 17:08:21
An even better solution is to simply check right after changing the score.

Yes, that's actually true. I noticed alot of people tend to do all the checks in repeatedly execute. My guess is that's simplier to just put everything there, instead of noting all the places where variables can be modified. Latter requires a good effort on systematizing the game logic, but it really pays off in the long run, especially with large projects.
Title: Re: repeatedly execute issue, is there a better way?
Post by: MrAbu on Sun 06/08/2017 02:06:02
Ohhhhh!!! that's sick! Thanks for all the different options! I'm currently working on a game while also learning how to make it and it's really fun to learn all this new stuff. and you guys are helping immensely. Thanks!