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

2013/12/17

how to let my ship get a crate

9
10
11
12
13
14
15
virginia001 virginia001

2013/12/29

#
nope.. all the trucks are null when a ship is docked...only the platform itself says the ship is hitting the platform
danpost danpost

2013/12/29

#
Are you assigning the 'platform' fields of the Vrachtwagen objects when creating them in the world class to the Vrachtwagenplek object?
virginia001 virginia001

2013/12/29

#
Yess..the platform for the trucks is been called Vrachtwagenplek and it's a subclass of Platform if that was your question
danpost danpost

2013/12/29

#
No, that was not my question. I was asking whether or not you were setting the 'platform' field of the Vrachtwagen objects after creating them in the world class. In other words, do you have something similar to line 3 of the following in the 'prepare' method of your world class for each of the truck objects being created?
Vrachtwagenplek platform = new Vrachtwagenplek();
Vrachtwagen truck = new Vrachtwagen();
truck.setPlatform(platform);
virginia001 virginia001

2013/12/29

#
This is my World class
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class Vracht extends World
{

    public Vracht()
    {    
        super(760,760, 1); 

        prepare();
    }

    private void prepare()
    {
        Platform platform = new Platform();    
        addObject(platform, 380, 652);    
        vrachtwagenplek vrachtwagenplek = new vrachtwagenplek();  
        addObject(vrachtwagenplek, 500, 126); 
        platform.setLocation(390, 651);
        vrachtwagenplek.setLocation(381, 53);
        
        VrachtwagenZwart vrachtwagenzwart = new VrachtwagenZwart();
        addObject(vrachtwagenzwart, 269, 122);
        VrachtwagenGroen vrachtwagengroen = new VrachtwagenGroen();
        addObject(vrachtwagengroen, 342, 125);
        VrachtwagenOranje vrachtwagenoranje = new VrachtwagenOranje();
        addObject(vrachtwagenoranje, 415, 123);
        VrachtwagenRood vrachtwagenrood = new VrachtwagenRood();
        addObject(vrachtwagenrood, 513, 127);
        VrachtwagenGeel vrachtwagengeel = new VrachtwagenGeel();
        addObject(vrachtwagengeel, 467, 119);

        vrachtwagengroen.setLocation(319, 121);
        vrachtwagenoranje.setLocation(388, 121);
        vrachtwagengeel.setLocation(454, 120);
        vrachtwagenrood.setLocation(514, 119);
        vrachtwagenzwart.setLocation(256, 122);
        groen groen = new groen();
        addObject(groen, 296, 596);
        groen groen2 = new groen();
        addObject(groen2, 502, 734);
        groen.setLocation(287, 590);
        groen2.setLocation(496, 727);
        oranje oranje = new oranje();
        addObject(oranje, 353, 596);
        oranje.setLocation(351, 590);
        oranje oranje2 = new oranje();
        addObject(oranje2, 291, 729);
        oranje2.setLocation(288, 726);
        paars paars = new paars();
        addObject(paars, 411, 667);
        paars.setLocation(412, 589);
        rood rood = new rood();
        addObject(rood, 502, 594);
        rood rood2 = new rood();
        addObject(rood2, 294, 664);
        rood2.setLocation(288, 661);
        paars.setLocation(426, 589);
        oranje.setLocation(356, 590);
        oranje.setLocation(358, 589);
        rood.setLocation(495, 589);
        zwart zwart = new zwart();
        addObject(zwart, 366, 665);
        zwart.setLocation(360, 660);
        zwart zwart2 = new zwart();
        addObject(zwart2, 436, 734);
        zwart2.setLocation(427, 728);
        geel geel = new geel();
        addObject(geel, 496, 660);
        geel geel2 = new geel();
        addObject(geel2, 361, 728);
        geel2.setLocation(359, 727);
        zwart.setLocation(359, 661);
        oranje2.setLocation(427, 663);
        paars paars2 = new paars();
        addObject(paars2, 294, 729);
        paars2.setLocation(288, 727);
        vrachtwagenzwart.setLocation(248, 122);
        vrachtwagengroen.setLocation(297, 121);
        vrachtwagenoranje.setLocation(358, 121);
        vrachtwagengeel.setLocation(421, 120);
        vrachtwagenrood.setLocation(476, 120);
        VrachtwagenPaars vrachtwagenpaars = new VrachtwagenPaars();
        addObject(vrachtwagenpaars, 525, 125);
        vrachtwagenpaars.setLocation(522, 120);
        vrachtwagenoranje.setLocation(350, 121);
        vrachtwagengeel.setLocation(407, 121);
        vrachtwagenrood.setLocation(468, 120);
        vrachtwagenrood.setLocation(467, 120);
        vrachtwagenrood.setLocation(461, 120);
        vrachtwagenpaars.setLocation(515, 120);

        Schipgroen schipgroen = new Schipgroen();
        addObject(schipgroen, 637, 96);
        schipgroen.setLocation(654, 96);

        platform.setLocation(390, 651);
        vrachtwagenplek.setLocation(381, 53);
        rood.setPlatform(platform);
        groen.setPlatform(platform);
        oranje.setPlatform(platform);
        paars.setPlatform(platform);
        rood2.setPlatform(platform);
        zwart.setPlatform(platform);
        oranje2.setPlatform(platform);
        geel.setPlatform(platform);
        paars2.setPlatform(platform);
        geel2.setPlatform(platform);
        zwart2.setPlatform(platform);
        groen2.setPlatform(platform);
        Lives lives = new Lives();
        addObject(lives, 34, 36);
        Lives lives2 = new Lives();
        addObject(lives2, 84, 43);
        Lives lives3 = new Lives();
        addObject(lives3, 136, 33);
        
        lives.setLocation(27, 25);
        lives2.setLocation(75, 24);
        lives3.setLocation(124, 24);
    }
}
danpost danpost

2013/12/29

#
I see where you set the 'platform' fields for the crates (lines 99 through 110). I do not see any code to set the 'platform' fields for the trucks. You need to add that.
virginia001 virginia001

2013/12/29

#
something like this..?
vrachtwagenzwart.setPlatform(platform);
        vrachtwagengroen.setPlatform(platform);
        vrachtwagenoranje.setPlatform(platform);
        vrachtwagengeel.setPlatform(platform);
        vrachtwagenrood.setPlatform(platform);
        vrachtwagenpaars.setPlatform(platform);
danpost danpost

2013/12/29

#
virginia001 wrote...
something like this..?
vrachtwagenzwart.setPlatform(platform);
        vrachtwagengroen.setPlatform(platform);
        vrachtwagenoranje.setPlatform(platform);
        vrachtwagengeel.setPlatform(platform);
        vrachtwagenrood.setPlatform(platform);
        vrachtwagenpaars.setPlatform(platform);
If 'platform' in this code refers to the Vrachtwagenplek object, then yes.
virginia001 virginia001

2013/12/29

#
I have changed to parameter from platform to vrachtwagenplek to make sure it is assigned to the truck platform objects...but the truck is still not getting the crate though because i can't pick up a crate after i clicked on a truck to load it in.
danpost danpost

2013/12/29

#
I did not think it was necessary to add a 'kratten' field to the truck objects as the truck will move up and off the screen when clicked on. Does the 'platform' field of the truck turn to null when a crate is hypothetically loaded by clicking on the truck?
virginia001 virginia001

2013/12/29

#
No it doesn't
danpost danpost

2013/12/29

#
Which one of the following conditions is not true when trying to load a crate from ship to truck? (a) platform.getSchip() != null, or (b) platform.getSchip().getKratten() != null One (or both) of them must be false to get those results (unless some other code in your project is messing with this - like something in the truck subclasses?).
virginia001 virginia001

2013/12/29

#
the platform of the truck does get the ship though so (a) is true as for (b) i inspected the ship but it still has the crate after clicking pon a truck
danpost danpost

2013/12/29

#
Please, re-share (update) your scenario on this site (use the same name you used last time). Do not forget to check the 'Publish source code' checkbox again.
virginia001 virginia001

2013/12/30

#
updated the scenario
There are more replies on the next page.
9
10
11
12
13
14
15