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

2014/9/15

HELP

BrownBoii333 BrownBoii333

2014/9/15

#
Hi I need help to make something go on forever. You see I want SafeTime to go up constantly while being in contact with my character until it hits 3000(3 seconds) then delete the object that my character is touching. I figured everything elseout except how to make the "SafeTime++;" to go up constantly instead of once. Help? public void imSafe(){ Actor Pardeep = getOneIntersectingObject(MiniGlade.class); if(Pardeep!=null){ SafeTime++; if(SafeTime==3000) { getWorld().removeObject(Pardeep); SafeTime=0; } else if ( SafeTime < 3000 ) { SafeTime = 0; } } }
Super_Hippo Super_Hippo

2014/9/15

#
You method does the following. If your character intersects an object of the class 'MiniGlade', it will increase 'SafeTime' by one. At the end, it will set to 0 again, because it is of course less then 3000. It will never reach 3000. In fact, it will never even reach 2. You also might want to know that 3000 act cycles are normally far over 3 seconds. Try this: (Maybe you should change the method name because 'imSafe' does not really refer to what the method does, I think.)
public void imSafe()
{
        Actor pardeep = getOneIntersectingObject(MiniGlade.class);
        if(pardeep != null)
        {
            safeTime++;
            if (safeTime == 3000)
            {
                getWorld().removeObject(pardeep);
                safeTime = 0;
            }
        }
        else if (safeTime < 3000)
        {
            safeTime = 0;
        }
    }
danpost danpost

2014/9/15

#
With the logic that is being used, the value of SafeTime will never be more than 1. As soon as you increment it, the 'else' part will set it back to zero. Also, the incrementing of its value, if allowed to make it to 3000, would probably last close to a minute (not 3 seconds). You probably should use a value between 150 and 180 to create an approximate 3 second safe time.
BrownBoii333 BrownBoii333

2014/9/16

#
IS there a way to make SafeTime to go up by more than once? Becuase I know that it won't reafch 3000 cuz it'll only go up once, but what i want to know is if there is a way to make SafeTime go up continuously until it reaches 3000. (or something else)
Super_Hippo Super_Hippo

2014/9/16

#
Did you try my code? Change the 3000 to something like 170 and see if it works. What I changed was, that the 'else' is in relation to the other 'if' now.
You need to login to post a reply.