Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 1962 times)
0 Members and 1 Guest are viewing this topic.
Offline JayTech

Junior Devvie

Medals: 1

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

Thanks all.

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

JGO Kernel

Medals: 508
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.

public void teGO() {
      new Thread(this).start();


   public void run() {


End result  
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.
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  

EgonOlsen (78 views)
2018-06-10 19:43:48

EgonOlsen (58 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (260 views)
2018-05-13 18:23:11

nelsongames (158 views)
2018-04-24 18:15:36

nelsongames (157 views)
2018-04-24 18:14:32

ivj94 (898 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (811 views)
2018-03-24 14:43:53

Solater (175 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!