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

2013/6/24

Code not working.

Hawx_ Hawx_

2013/6/24

#
public void shootWarp()
    {
        if ("V".equals(Greenfoot.getKey())) {
            if( ((((Space) getWorld()).WarpGun )== 100 ) ){
                Enterprise_WarpGun ew = new Enterprise_WarpGun();  
                getWorld().addObject(ew, getX(), getY());

            }
            (((Space) getWorld()).WarpGun) = 0;
        }
    }
Hi, I need some help with this code, In theory this code should make a new bullet when WarpGun int reaches 100. And then should reset the int to 0 again. But it's not working, no errors , just doesn't work. Thanks , Hawx
davmac davmac

2013/6/24

#
You should normally use Greenfoot.isKeyDown(...) rather than Greenfoot.getKey(). Are you calling Greenfoot.getKey() somewhere else? In that case the other call may be consuming the keystroke before this code sees it. Also, the way you have written the code above requires a capital 'V' to be typed - i.e. you must be holding shift while you press V. Another possibility is that you have forgotten to call the shootWarp() method, or you are calling it from the wrong place.
Zamoht Zamoht

2013/6/24

#
I don't know if this is the problem, but right now you have to hold down shift or use caps lock to make getKey() be equal to "V". What I'm saying is that you might fix the problem by changing if ("V".equals(Greenfoot.getKey())) { to if ("v".equals(Greenfoot.getKey())) { Please tell me if this doesn't fix it. (Didn't see davmac's post)
You need to login to post a reply.