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

2015/4/18

Help. when try to put down multiple objects only one appears.

Hombow Hombow

2015/4/18

#
I'm writing a code and I want objects to appear randomly across a row but only one appears at a time. it appears in the correct spots. I'm using a for loop that appears to work correctly but I'm not sure whether it stops after the object is placed or if the object just can't be placed again
Super_Hippo Super_Hippo

2015/4/18

#
Show the code. I guess, you do something like this:
ClassName c = new ClassName();
for (...;...;...)
{
    addObject(c, ..., ...);
}
If that the case, then move the first line into the for loop. If it is outside, then you are trying to add the same object more than once into the world which doesn't work.
Hombow Hombow

2015/4/18

#
that's the code, if adding the same object more than once doesn't work, then how would I add the same object more than once?
Hombow Hombow

2015/4/18

#
Wall wall = new Wall();
for(int i = 0; i < 100; i++)
{
    if(Greenfoot.getRandomNumber(4) > 2)
    {
            addObject(wall,2 + (i*4),396);
    }    
}
heres the code
Hombow Hombow

2015/4/18

#
thank you sorted it out
You need to login to post a reply.