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

2017/12/14

Why does this not work?

1
2
Simon1122111 Simon1122111

2017/12/14

#
public void act() { A=Greenfoot.getRandomNumber(1000); if(A <= 20) { this.getWorld().addObject(new Auto7(), 400,450); } }
danpost danpost

2017/12/14

#
Simon1122111 wrote...
Why does this not work? < Code Omitted >
Are you getting an error message? if so, what does it say?
Simon1122111 Simon1122111

2017/12/14

#
im not getting an error message but it doesnt add the Object
danpost danpost

2017/12/14

#
Simon1122111 wrote...
im not getting an error message but it doesnt add the Object
What code do you have in the Auto7 class?
Simon1122111 Simon1122111

2017/12/14

#
all i want is this: ive got 7 different objects and i want greenfoot to add a random one of it in a random timeinterval
Simon1122111 Simon1122111

2017/12/14

#
this is the code of the auto7 class
danpost danpost

2017/12/14

#
Simon1122111 wrote...
all i want is this: ive got 7 different objects and i want greenfoot to add a random one of it in a random timeinterval
In what class is the 'act' method above? I hope it is not in a class of one of those 7 objects.
Simon1122111 Simon1122111

2017/12/14

#
it is....
Simon1122111 Simon1122111

2017/12/14

#
ive got this code in all 7 classes
danpost danpost

2017/12/14

#
Simon1122111 wrote...
it is....
That is the problem, then. The act method will run for each object of its class during the time it is in the world. If none are in the world, the code will not execute. Use the 'act' method in your World subclass to perform the duty of randomly spawning objects (add an act method there if you do not already have one there.
Simon1122111 Simon1122111

2017/12/14

#
i tryed that before in my Wo rld but if(A > 20 && A < 40) { Auto2 a2 = new Auto2(); addObject(a2, 400,450); } didnt work
danpost danpost

2017/12/14

#
Simon1122111 wrote...
i tryed that before in my World but
if(A > 20 && A < 40)
{  
    Auto2 a2 = new Auto2();
    addObject(a2, 400,450);
}
didnt work
Show the code for the World subclass so that the placement of given code can be confirmed to be correct.
Simon1122111 Simon1122111

2017/12/14

#
oh i fixed it. Thank you. But ive got annother problem. I want my object to spawn neither at x=350, x=400 or x=350 (random wich one) how can i do that?
danpost danpost

2017/12/14

#
Simon1122111 wrote...
I want my object to spawn neither at x=350, x=400 or x=350 (random wich one)
You are showing 350, 400 and ???; is it supposed to be 350 (again)?
Simon1122111 Simon1122111

2017/12/14

#
no i meant 450
There are more replies on the next page.
1
2