Results 1 to 4 of 4
  1. #1
    walkineagle is offline Member
    Join Date
    Apr 2011
    Posts
    7
    Rep Power
    0

    Smile Beginner Java Modding Problem...

    Hello im trying to use Keyboard.isKeyDown to create a way to make it so if the button is pressed something will happen and if I press the button again it will stop. I have the basic concept worked out, and I HAD it working with another thing but for some reason this code won't work (im making mods for a Java game using Java Eclipse EE):
    Java Code:
    		if(Keyboard.isKeyDown(36) && buttonpress==false){
    			buttonpress=true;
    			whattodo=!whattodo;
    		}
    		if(!Keyboard.isKeyDown(36)){
    			buttonpress=false;
    		}
    		if(whattodo=false){
    			moty=0.41999998688697815D;
    		}
    		if(whattodo=true){
    			moty=0.71999998688697815D;
    		}
    whattodo and buttonpress are booleans and moty is a double. moty is the variable for MotionY. Later on in this code I use this (or something like it, its not the exact code) to call it

    Java Code:
    Public class Jump(){
    MotionY = moty;
    }
    Im trying to make it so when I press "J" or J = true MotionY is .3 higher (A very noticable difference)
    Last edited by walkineagle; 04-13-2011 at 02:37 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Use a Swing Timer. I would also use key binding rather than a key listener to check for key press.

    Also, this is messed up:

    Java Code:
    		if(whattodo=false){
    			moty=0.41999998688697815D; // ??? what's the D for ???
    		}
    		if(whattodo=true){
    			moty=0.71999998688697815D;
    		}
    You are not checking for equality which uses ==, but you don't even want to. To check if a boolean is true you simply do

    Java Code:
    		if (!whattodo) {
    			moty=0.41999998688697815;
    		} else {
    			moty=0.71999998688697815;
    		}

  3. #3
    walkineagle is offline Member
    Join Date
    Apr 2011
    Posts
    7
    Rep Power
    0

    Default

    Okay so I tried this and it doesn't work... MotionY always stays at the .4 one.
    Java Code:
        protected void jump()
        {
    		if(Keyboard.isKeyDown(36) && !buttonpress){
    			buttonpress=true;
    			whattodo=!whattodo;
    		}
    		if(!Keyboard.isKeyDown(36)){
    			buttonpress = false;
    		}
    		if (!whattodo) {
    			moty=0.41999998688697815D;
    		} else {
    			moty=0.71999998688697815D;
    		}
            motionY = moty;
        }

  4. #4
    walkineagle is offline Member
    Join Date
    Apr 2011
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Beginner Problem
    By Freakzoyd in forum New To Java
    Replies: 6
    Last Post: 07-20-2010, 01:23 PM
  2. Beginner in Java - need some help
    By ea09530 in forum Advanced Java
    Replies: 4
    Last Post: 04-05-2010, 11:47 PM
  3. java beginner
    By devstarter in forum New To Java
    Replies: 4
    Last Post: 03-03-2010, 08:39 AM
  4. Java Beginner needs help!!
    By Polyy in forum New To Java
    Replies: 4
    Last Post: 11-23-2008, 02:11 AM
  5. beginner to Java
    By notwist in forum New To Java
    Replies: 15
    Last Post: 04-18-2008, 09:41 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •