This site requires JavaScript, please enable it in your browser!
Greenfoot back
joandvgv
joandvgv wrote ...

2015/2/18

Pausing movement when there's one equal actor.

1
2
3
4
5
6
danpost danpost

2015/2/19

#
How do you set the value of 'capacidad'? (show declaration, assignment and any changes to its value)
joandvgv joandvgv

2015/2/19

#
//class constructor  
public int capacidad=1000;
// act method

   private void recoger()
    {
        Actor punto = getOneObjectAtOffset(0, 0, Punto.class);
        if(punto != null) {
            getWorld().removeObject(punto);
            capacidad =  capacidad - randomNum; 
            informacion.contador1(capacidad);
            infoparada.contador(randomNum);
            recogido=true;
        }
    }   
         
I don't change its value anywhere but in that method.
joandvgv joandvgv

2015/2/19

#
Tryng to see that happens I noticed that the condition is met by the first time when the truck reaches the first point. (when it finds garbage to pick)
danpost danpost

2015/2/19

#
I presume that line 2 is actually a field declared in the class (not actually in the constructor as line 1 indicates). I do not know if this will change things much; but, the check at the end of the act method is being done AFTER collection has occurred which changes the value of 'capacidad'. That comparison should be done before collection, as the values you actually want to compare are current at that time.
danpost danpost

2015/2/19

#
How about the 'recogido' field. Show its declaration, assignment, usage, etc.
joandvgv joandvgv

2015/2/19

#
Well, that did change things. Now the condition is not always met, that's what I wanted. But I realized that when the truck stops for a few seconds, I keep getting randomNumbers. I think that causes that even if at the beginning the condition is met (Cantidad<randonNumber) it will still pick it. So, the thing now is that the truck says a new truck is needed but it does collect the garbage (so it shouldnt be needed)
danpost danpost

2015/2/19

#
As far as the 'if' block, lines 22 to 24 of the act method above, remove those lines and replace lines 9 through 12 with the following:
if(haybasura() && (capacidad>randomNum) && empezarrecoleccion()) {
    if (capacidad<randomNum) {
        necesitacarro = true;
    }
    else {
        pauseTimer=361;
        recoger(); //pick up
    }
}
joandvgv joandvgv

2015/2/19

#
Recogido is something I was trying in order to just get a randomNumber when the truck finds garbage and not every act call as it is actually doing, but its still doing the same.
    private boolean recogido=false;

    private void recoger()
    {
        Actor punto = getOneObjectAtOffset(0, 0, Punto.class);
        if(punto != null) {
            getWorld().removeObject(punto);
            capacidad =  capacidad - randomNum; 
            informacion.contador1(capacidad);
            infoparada.contador(randomNum);
            recogido=true; //here i change the value because it picked up the garbage
        }
    }   
Of course, now I know this does not work at all because once it is true it's never gonna be false again, so it will always generate RandomNumbers in every act call..
danpost danpost

2015/2/19

#
Line 1 in my previous code post should be the following:
if(haybasura() && empezarrecoleccion()) {
joandvgv joandvgv

2015/2/19

#
danpost wrote...
As far as the 'if' block, lines 22 to 24 of the act method above, remove those lines and replace lines 9 through 12 with the following:
if(haybasura() && (capacidad>randomNum) && empezarrecoleccion()) {
    if (capacidad<randomNum) {
        necesitacarro = true;
    }
    else {
        pauseTimer=361;
        recoger(); //pick up
    }
}
One of the condition of the main if is:
&& (capacidad>randomNum)
If I replace that and inside that if, i write the new condition capacidad<randomNum, would that coundition ever met? EDIT: Didn't see your last post. Now it's ok. But how about the random values with every act call? Does that matter?
danpost danpost

2015/2/19

#
The random values every act call MAY matter. What do the methods 'haybasura' and 'empezarrecoleccion' check? (show codes)
joandvgv joandvgv

2015/2/19

#
I think it does matter, becuase i've changed what you said and it works but as i said above:
I realized that every act call i get a new random Number. and I think that causes that even if at the beginning the condition is met (Cantidad<randonNumber) it will still pick it. So, the thing now is that the truck says a new truck is needed but it does collect the garbage (so it shouldnt be needed)
joandvgv joandvgv

2015/2/19

#
   private boolean haybasura() //This just returns true if found garbage. 
    {
        Actor punto = getOneObjectAtOffset(0, 0, Punto.class);
        if(punto != null) {
            return true;
        }
        else {
            return false;
        }
    }
Empezarrecoleccion just tell the truck when to start picking up depending on its route:
private boolean empezarrecoleccion(){
       switch (numruta){
            case 1: {
                if (pasosaux>=481) return true;
                break;
            }
            case 2: {
                if (pasosaux>=36) return true;
                break;
            }
            case 3: {
                if (pasosaux>=200) return true;
                break;
            }
            case 4: {
                if (pasosaux>=540) return true;
                break;
            }
            case 5: {
               if (pasosaux>=400) return true;
                break;
            }
            default: {
                break;
           }
     }
     return false;
 }  
danpost danpost

2015/2/19

#
I do not think it matters because 'haybasura' makes sure that garbage is there to be collected and neither the 'recoger' method is called nor the check to determine if a new truck is needed are executed unless the garbage is there (when 'recoger' is executed the first time, the garbage is removed; so processing will only be done once).
danpost danpost

2015/2/19

#
I am a bit confused. If the 'recogido' field starts as 'false' and is only changed in the 'recoger' method which is only called if the 'recogido' field is 'true' -- how can the 'recoger' method ever get executed at all !?!
There are more replies on the next page.
1
2
3
4
5
6