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

2013/4/4

Store Opening Problem

GrimCreeper312 GrimCreeper312

2013/4/4

#
my games is at http://www.greenfoot.org/scenarios/7947 or InvadersHelp when the round ends the store is supposed to come up it works the first time then the next time it comes up only for a brief second.
well i looked through your code (not all of it) and found this:
public void closeStore()
{
    if(storeClosed == true)
    ...
    storeClosed = false;
}
Never in your code (of the world) do you say to turn storeClosed into true. And why do you have a storeClosed variable? If storeOpened = false, then you know the store is closed. I would recommend changing your code a bit to have only the storeOpened variable. That might fix your problem.
GrimCreeper312 GrimCreeper312

2013/4/4

#
i need that for a method to work
need what?
danpost danpost

2013/4/4

#
If using 'storeClosed' for a method to work, it will work just as well with '!storeOpened'. If using 'storeOpened' for a method to work, it will work just as well with '!storeClosed'. The '!' changes the value from true to false or from false to true (basically read as 'not').
that's probably what I should've said... Here's an example
openStore = true;
System.out.println(openStore); //Would print "true"
System.out.println(!openStore); //Would print "false"
GrimCreeper312 GrimCreeper312

2013/4/4

#
i have changed it to only have storeOpen but i still get the error i believe that the error is because the store gets added then immeditally removed
GrimCreeper312 GrimCreeper312

2013/4/4

#
my game should be updated in a min
GrimCreeper312 GrimCreeper312

2013/4/4

#
maybe the error is caused in the openStore() or closeStore() methods in the world but i cant figure out whats wrong
danpost danpost

2013/4/4

#
It looks to me like the store is to open when 'round' is set to one. At least 'storeOpen' is called then; and 'round' is then reset to zero (in the 'checkRound' method of the Atmosphere class). Then, the next 'act' method will execute its first line, calling the 'closeStore' method with 'round' now equal to zero. Therefore, the store will remain closed until 'round' is reset back to one. I noticed that you have many, many unnecessary boolean fields in your scenario. Mainly those that reflect if an object is in the world or not. Instead of using these fields, which requires an extra step every time an object is added or removed from the world, better would be to use statements like the following:
// instead of
if (isBarrier1 == true)
// use
if (barrier1.getWorld() != null)
There are many other places your code could be improved. As an example, your 'barriers' method could be simplified to:
public void barriers()
{
    if (boughtBarriers)
    {
        removeObjects(getObjects(Barrier.class));
        addObject(barrier1, 200, 425);
        addObject(barrier2, 500, 425);
        addObject(barrier3, 800, 425);
    }
}
The first statement removes any barrier object in the world (your first three 'if's basically says 'if any barrier is in the world, remove it', which is the same as 'remove all barriers in the world'). Your last three 'if's are unnecessary because you know that all barriers are now removed from the world and you do not need to ask.
GrimCreeper312 GrimCreeper312

2013/4/4

#
i have shortened the barriers method. I found the problem in button the variable q was not resetting to 0;
You need to login to post a reply.