Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: steptoe on Wed 07/12/2011 15:59:53

Title: SOLVED: DoOnceOnly problem
Post by: steptoe on Wed 07/12/2011 15:59:53
Hi

Somehow trying to only add to score just once.


  if (cspit.PPCollidesWithO(obottle1))
 
 {  

  aBOTTLE_SMASH3.Play();
  aCheer.Play();
  object[11].Visible=true;
 
if (Game.DoOnceOnly("bottle1"))  // does not work
 
   Points=(Points +1);
  object[0].SetView(7, 0);
  object[0].Animate(0, 4, eRepeat, eNoBlock);
  cspit.Move(cspit.x + 0, cspit.y + 120, eNoBlock, eWalkableAreas);
  cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
 
}
[/coder]



Title: Re: Score not adding up correctly, misses 1 point in condition
Post by: Adrian on Wed 07/12/2011 16:35:48
Hm, at first sight I can see no reason why only 4 points are added instead of 5. But in my opinion you don't need the first part of the script at all, where you check repeatedly if an object is visible and then add points. You can simply put the addition in the second part where you check for collision. Something like this:


if (cspit.PPCollidesWithO(obottle1))
 
 {  

  aBOTTLE_SMASH3.Play();
  aCheer.Play();
  object[11].Visible=true;
  object[0].SetView(7, 0);
  object[0].Animate(0, 4, eRepeat, eNoBlock);
  cspit.Move(cspit.x + 0, cspit.y + 120, eNoBlock, eWalkableAreas);
  cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);

  if (Game.DoOnceOnly("bottle1b"))
{
   Points=(Points +1);
 
}
}

Comment out the first part of the script and add the "Points +1" part to the collision checks. Maybe this will do the trick.

Also note that when you set up the timer in the third part of the script, int ran=Random(2); will create a random number from 0 to 2, which means 0, 1 or 2. So this line:
else if (ran == 3)
will never be true.

Oh, and please don't double post.
Title: Re: .DoOnceOnly problem
Post by: steptoe on Wed 07/12/2011 17:01:05
i forget to take random int out.. cheers

Also the Game.DoOnceOnly is NOT working as it can score more than once!


if (cspit.PPCollidesWithO(obottle1))
   


   aBOTTLE_SMASH3.Play();
   aCheer.Play();
   object[11].Visible=true;
   object[0].SetView(7, 0);
   object[0].Animate(0, 4, eRepeat, eNoBlock);
   cspit.Move(cspit.x + 0, cspit.y + 120, eNoBlock, eWalkableAreas);
   cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
   
   if (Game.DoOnceOnly("bottle1a"))
   {
   Points=(Points +1);
   
  }}


Title: Re: SOLVED: DoOnceOnly problem
Post by: monkey0506 on Wed 07/12/2011 19:29:23
This is marked as solved, but you said that Game.DoOnceOnly is still not working. Game.DoOnceOnly does work. It will never return true more than once for the same string token during a single run of your game. Ever.
Title: Re: SOLVED: DoOnceOnly problem
Post by: steptoe on Thu 08/12/2011 07:31:13
Hi Monkey

Each string is different and it all works now.

I just had an overload  :=

cheers

steptoe


Title: Re: SOLVED: DoOnceOnly problem
Post by: Matti on Thu 08/12/2011 08:28:41
Btw, instead of Points=(Points +1) you can just write Points ++, or, if more is added, Points += x.
Title: Re: SOLVED: DoOnceOnly problem
Post by: steptoe on Fri 09/12/2011 04:16:13
Thanks for all your replies guys

:=