Score not all adding up with conditions

Started by steptoe, Wed 07/12/2011 15:43:28

Previous topic - Next topic

steptoe

Hi

I can't see the problem I obviously have in this script.

Scenario: 5 bottles. Hit each bottle and it changes view and another object is visible.

You receive 1 point (Point Int) every time a bottle is hit (when other object becomes visible.)

You should receive 5 points for all bottles smashed.

Unfortunately it misses a point.

It does not matter in which order you do the problem of points still prevails, it misses giving one point.

Hopefully someone will sort out my cockup  ::)

Code: ags


function room_RepExec()
{
  
   cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
 
  
  if(object[11].Visible)
  if (Game.DoOnceOnly("bottle1b"))
{
    Points=(Points +1);
  
}
  if(object[12].Visible)
  if (Game.DoOnceOnly("bottle2b")) 
{
    Points=(Points +1);
    
}
  if(object[13].Visible)
  if (Game.DoOnceOnly("bottle3b")) 
  {
    Points=(Points +1);
    
}
  if(object[14].Visible)
  if (Game.DoOnceOnly("bottle4b")) 
{
    Points=(Points +1);
    
}
  if(object[15].Visible)
  if (Game.DoOnceOnly("bottle5b")) 
{
    Points=(Points +1);
  }
  
  
  
   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 (cspit.PPCollidesWithO(obottle2))
 
  
{
   aBOTTLE_SMASH3.Play();
   aCheer.Play();
   object[12].Visible=true;
   object[1].SetView(7, 0);
   object[1].Animate(0, 4, eRepeat, eNoBlock);
   cspit.Move(cspit.x + 0, cspit.y + 120, eNoBlock, eWalkableAreas);
   cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
   
}
   if (cspit.PPCollidesWithO(obottle3))
 
  
{
    aBOTTLE_SMASH3.Play();
    aCheer.Play();
    object[13].Visible=true;
    object[2].SetView(7, 0);
    object[2].Animate(0, 4, eRepeat, eNoBlock);
    cspit.Move(cspit.x + 0, cspit.y + 120, eNoBlock, eWalkableAreas);
    cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
   
}
    
 
 if (cspit.PPCollidesWithO(obottle4))

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

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

  if (Spit == 0 && Points < 9)
 
  {
   aRound2.Play();
   cEgo.Say("I need to produce more spit!");
   object[0].Move(200, 92, -1, eNoBlock, eAnywhere);
   object[1].Move(200, 92, -1, eNoBlock, eAnywhere);
   object[2].Move(200, 92, -1, eNoBlock, eAnywhere);
   object[3].Move(200, 92, -1, eNoBlock, eAnywhere);
   object[4].Move(200, 92, -1, eNoBlock, eAnywhere);
   
   
   object[16].SetView(8, 0);
   object[16].Animate(0, 4, eRepeat, eNoBlock);
   object[16].Move(185, 110, 2, eBlock);
   object[15].Visible=false;
   object[16].Move(173, 110, 2, eBlock);
   object[14].Visible=false;
   object[16].Move(153, 110, 2, eBlock);
   object[13].Visible=false;
   object[16].Move(134, 110, 2, eBlock);
   object[12].Visible=false;
   object[16].Move(117, 110, 2, eBlock);
   object[11].Visible=false;
   object[16].Move(20, 97, 2, eBlock, eAnywhere);
   
   
   SetNextScreenTransition(eTransitionInstant);
   cspit.ChangeRoom(4);
   cEgo.ChangeRoom(4);
 
}




 if (cspit.PPCollidesWithO(oback))
  
{
   int ran=Random(2);
     
    if (ran == 0)
    
  {
    
      aComeoneddie.Play();
      aBoo.Play();
      
   }
     else if (ran == 1) 
  {
     aNochance.Play();
     aBoo.Play();
      
 }
     else if (ran == 2) 
  {
     aRouting.Play();
     aBoo.Play();
      
 }
     else if (ran == 3)
   {
     aNochanceagainst.Play();
     aBoo.Play();
      
}}






Khris

If you say the order doesn't matter, which point is missed, the last one?

Try this:

Code: ags
function room_RepExec()
{
  int b;
  while (b < 5) {
    if (cspit.PPCollidesWithO(object[b])) {
      aBOTTLE_SMASH3.Play();
      aCheer.Play();
      object[b+11].Visible=true;
      object[b].SetView(7, 0);
      object[b].Animate(0, 4, eRepeat, eNoBlock);
      cspit.Move(cspit.x + 0, cspit.y + 120, eNoBlock, eWalkableAreas);
      cspit.FollowCharacter(cEgo, FOLLOW_EXACTLY);
      if (Game.DoOnceOnly(String.Format("bottle%db", b+1))) Points++;
    }
  }

  if (cspit.PPCollidesWithO(oback))
  {
    int ran = Random(3);
     
    if (ran == 0) aComeoneddie.Play();
    else if (ran == 1) aNochance.Play();
    else if (ran == 2) aRouting.Play();
    else if (ran == 3) aNochanceagainst.Play();

    aBoo.Play();
      
  }
}


Btw, I don't think the eNoBlock-Move command does anything; FollowCharacter comes right after and should override any effect.
If you just want to instantly change the position, you can set the coordinates directly:

Code: ags
    cspit y = cspit.y + 120;


steptoe

Hi Khris

I have solved it now...

Noeblock because i did not want it to stop other stuff from animating.

cspit is a weapon that shoots out (preset Y)  from playerand then returns for next use. I've got it in the Global script.

Thanks for Random Tip

cheers

;)




Khris

I realize why you are using eNoBlock, I merely pointed out that it won't give the desired result.
You don't want to move the character visible, you just want to change its position.

What you're looking for is:
Code: ags
  cspit.x = cEgo.x;
  cspit.y = cEgo.y + 120;


This code will move the cspit character to a position 120 pixels below cEgo, and most importantly, it'll do so instantly.

As for solving this, did my code help at all...?

SMF spam blocked by CleanTalk