Results 1 to 14 of 14
  1. #1
    derick is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default Rechecking an integer after starting a void.

    Here's my problem: I create a void that does stuff, pause for 15 seconds, then does more stuff. But I need it to check for the current integers after the pause, not the ones that existed at the start of the method.
    Currently I'm doing something like this, but removed the insides.
    Java Code:
    public void blahblah() {
    statemnets;
    statements;
    try {
    Thread.sleep(15500);
    } catch(InterruptedException e){}
    System.out.println(getSomething+"I want that what is is currently, not at the beginning");

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

    Default

    Quote Originally Posted by derick View Post
    ... But I need it to check for the current integers after the pause, not the ones that existed at the start of the method....
    Can you clarify this greatly? And welcome to the java-forums!

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,250
    Rep Power
    25

    Default

    I can not understand Your description of your problem.
    Can you use programming terminology? voids? current integers? removed insides?

  4. #4
    derick is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default

    I'm sorry, I've never posted on a java forum, and I taught myself. I apologize if I'm not clear.

    I'll try to explain again. When you start this method, it uses the thread.sleep method to pause the method for 15 seconds. After the pause, I want the method to return a value that has changed since the beginning of the initialization of the method.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,250
    Rep Power
    25

    Default

    I want the method to return a value
    The method returns void ie nothing. you'll have to change its defintion to return a value.

    value that has changed
    How do you determine that? Do you save it somewhere so it can be returned?

    You'll have to post more of the code or this will take a long time.

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

    Default

    I'm still not quite clear on what you are trying to do, but it sounds as if you have properties that may or may not have been changed during the method's run, and perhaps you need to store their initial value at the beginning of the method and somehow loop through them at the end, comparing the values.

    If you want more help from me, you're really going to have to provide more detail, much more. Please read the 2nd link in my signature, "how to ask smart questions", as it will give you valuable insights into how to ask questions here that are answerable. It has helped me and can help you too.
    Last edited by Fubarable; 07-11-2010 at 05:01 AM.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,250
    Rep Power
    25

    Default

    Just read parts of it: "how to ask smart questions". Excellent. I'll have to read some more next go around.

  8. #8
    derick is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default

    Here's my real code if it helps at all. The "how to ask smart questions" didn't really help me "ask questions".
    Java Code:
    class eh {
    
        static void execute(Client c, String[] split, char heading, boolean answer) {
            GameServer game = c.getGameServer();
            Character player = c.getPlayer();
            boolean participate = true;
            boolean pass;
            if (split[0].equals("test")) {
                try { Thread.sleep(15500); }
                catch(Exception e) {}
            }
            for (Character m : player.getMap().getCharacters()) {
                if (m != null) {
                    if (m.getPosition().x > -308 && m.getPosition().x < -142)
                        participate = false;
                    else if (m.getPosition().x <= -308) {
                        pass = true;
                } else if (m.getPosition().x >= -142) {
                      pass = false;
                } if (pass == answer && participate) {
                    System.out.println(m.getName()+" is right.");
                } else if (pass != answer && participate) {
                    System.out.println(m.getName()+" is wrong.");
                }
             }
        }
        }
    }
    edit: some extra info to help you understand:
    This is a game of mine where the players in it are changing coordinates. You notice that there's a sleep method at the beginning. At the boolean "if (m.getPosition().x > -308 && m.getPosition().x < -142)", I want to find out if it's possible to check the position of the character nowi instead of the time of the initialization. If so, how to do that. I hope you won't make me post the source code for my entire game since it's very large...
    Last edited by derick; 07-11-2010 at 05:07 AM.

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

    Default

    Based on your code, I've no idea. Again, that link helped me, and I sincerely think that if you re-read it, especially the section titled "Be precise and informative about your problem", it will give valuable hints to help you post answerable questions. As is, I feel that your question involves too much information that we have absolutely no way of knowing.

    I am hopeful that Norm or other posters will be more astute than me and will be able to glean some insights that I've missed.

    Much luck.

  10. #10
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by derick View Post
    After the pause, I want the method to return a value that has changed since the beginning of the initialization of the method.

    then declare your method with the return type of your variable and inside the method make a call return variable.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by derick View Post
    Here's my problem: I create a void that does stuff, pause for 15 seconds, then does more stuff. But I need it to check for the current integers after the pause, not the ones that existed at the start of the method.
    Currently I'm doing something like this, but removed the insides.
    Please don't make up your own terminology; to most of the other people here, it doesn't make sense because there are severe mismatches with the 'official' (mind the quotes) terminology. You can't create a void; you can create methods that return a void type (i.e. nothing). There are no 'current integers'; you probably wanted to say the current value of some ints. 'Removing the insides' is more like 'cutting out its intestines' but I find that connotation quite humerous. Please stick with the 'normal' (again those quotes) terminology if you want your question to be understood.

    kind regards,

    Jos

  12. #12
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    You say that you " want to find out if it's possible to check the position of the character nowi instead of the time of the initialization"

    Can you tell us how you are storing the character, and how it would be changed?
    Is it all wrapped up in an object?

    If its in an object, simply pass the method a reference to the object, and when you need to get the character you can call yourObject.getCharacter() to get the character as it is right now.

    If you are using threads make sure that the methods are synchronised properly- by using a lock or similar method.

    Berkeleybross

  13. #13
    derick is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default

    @josah
    If I knew the 'normal' terminology I would've used it. :) Like I stated above, I taught myself.

    @ berkeleybross
    Thanks for that, it helped. I was using objects btw.

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by derick View Post
    @josah
    If I knew the 'normal' terminology I would've used it. :) Like I stated above, I taught myself.
    Hats off for that; non native English speakers (like me) just don't understand your terminology; if you get that right you'll be widely understood.

    kind regards,

    Jos

Similar Threads

  1. convert unsigned integer to signed integer in java?
    By diskhub in forum New To Java
    Replies: 6
    Last Post: 05-17-2010, 12:50 AM
  2. Int equals void
    By Insomniac Riot in forum New To Java
    Replies: 14
    Last Post: 05-06-2010, 03:44 PM
  3. Replies: 5
    Last Post: 01-24-2008, 11:53 PM
  4. is void a type?
    By mary in forum New To Java
    Replies: 3
    Last Post: 08-01-2007, 08:12 PM

Posting Permissions

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