Results 1 to 14 of 14
- 07-11-2010, 04:16 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
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");
-
- 07-11-2010, 04:37 AM #3
I can not understand Your description of your problem.
Can you use programming terminology? voids? current integers? removed insides?
- 07-11-2010, 04:41 AM #4
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
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.
- 07-11-2010, 04:44 AM #5
The method returns void ie nothing. you'll have to change its defintion to return a value.I want the method to return a value
How do you determine that? Do you save it somewhere so it can be returned?value that has changed
You'll have to post more of the code or this will take a long time.
-
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.
- 07-11-2010, 04:57 AM #7
Just read parts of it: "how to ask smart questions". Excellent. I'll have to read some more next go around.
- 07-11-2010, 05:03 AM #8
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
Here's my real code if it helps at all. The "how to ask smart questions" didn't really help me "ask questions".
edit: some extra info to help you understand: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."); } } } } }
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.
-
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.
- 07-11-2010, 07:39 AM #10
- 07-11-2010, 08:01 AM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
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
- 07-11-2010, 11:47 AM #12
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
- 07-11-2010, 09:11 PM #13
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
@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.
- 07-12-2010, 07:44 AM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
convert unsigned integer to signed integer in java?
By diskhub in forum New To JavaReplies: 6Last Post: 05-17-2010, 12:50 AM -
Int equals void
By Insomniac Riot in forum New To JavaReplies: 14Last Post: 05-06-2010, 03:44 PM -
The different of static void,protected,and void in methods?
By Winarto in forum New To JavaReplies: 5Last Post: 01-24-2008, 11:53 PM -
is void a type?
By mary in forum New To JavaReplies: 3Last Post: 08-01-2007, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks