Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  <Solved>Method not working w/o Sys.outs...Please help am baffled  (Read 786 times)
0 Members and 1 Guest are viewing this topic.
Offline JayTech

Junior Devvie


Medals: 1



« Posted 2012-05-28 21:45:37 »

<Solved>
Thanks all.


Apparently threads don't like boolean methods ><. My headache is gone alas!
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-05-28 22:28:18 »

What do you mean "doesn't work"? How do you tell if a method works or not?

Offline UprightPath
« Reply #2 - Posted 2012-05-28 22:57:52 »

Simply looking at the code, I can see several... Perhaps not errors, but places where it seems as though there could be something "wrong" going on.

I'm going to assume that your code is either single threaded or correctly synchronized. If either of these conditions are untrue, then it's likely that you're dealing with what's called a Heisenbug, which is to say: You've got a classic multi-thread error in there and the 'System.out' is causing it to run correctly because it provides an extra space for your multiple threads to interleave.

Line 9: You set eventAlive = true, then in line 7 you set it again.
Line 10 and 16: This should be an if else, instead of two ifs (The conditions are mutually exclusive).
Line 8: Unless something else, IE- TEtarget.GEStart(), updates currTime or TimeWizard.mainTimeSecs then the if statement will always hit either the if or the else for each repetition.
Line 6: Unless eventContinue is changed by TEtarget.GEStart() then line 37 is never reached.
Line 6: I'm assuming that TEtarget.GEStart() will update something, otherwise your loop will never expire.

A bit more information about what's supposed to be happening with the code could be useful, 'cause otherwise all of my observations are shots in the dark, so to speak.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JayTech

Junior Devvie


Medals: 1



« Reply #3 - Posted 2012-05-28 23:25:41 »

Meaning it doesn't work is that the thread just doesn't go/stop if I take the Sys outs away.
The object of this method is to start a loop which it looks at my games System time and takes a snapshot of the current time and then designated time to time something for example if its 30secs game time and you want 5seconds of something to start or sleep it goes till 35secs then terminates.

TEtarget.GEStart(); is the TimerEvent classes calling to a Interface method  GEStart which is passed through the constructor during initialization of the object. GeStart can be anything its just like Runnable.

 if (TimeWizard.mainTimeSecs <= currTime) once false it = else and  eventContinue to false ending the while loop.

Btw this is added to a thread.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public void teGO() {
      new Thread(this).start();

   }

   @Override
   public void run() {
      this.startEvent();

   }


End result  
1  
new TimedEvent(9,this).teGO();


Pretty much this class is a custom timer running by my games system time. Any entity or object can use this to trigger events because I have a method which tells once this is finished or not via TimerEvents method which other classes check.
1  
2  
3  
public boolean eventStatus() {
      return eventAlive;
   }


You are able to pick a time to Run during the duration say for 5 seconds or choose to go after 5 seconds  eventForDuration =true then it goes for the designated duration otherwise false it goes after the set duration.


So yea it appears my thread is just hanging for some reason.

EDIT: Solved..yea changing from a boolean to a void fixed things and just cleaning the code a bit, thanks guys UprigthPath good calls btw.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (69 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (82 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!