Game loop logic?

Hey all,
I'm looking for some help in the logic department instead of specific code help;
I'm currently working (or trying, anyway) to make a Java ME game for my mobile. Essentially, it's a little arcade shooter: ship shoots asteroid, you get the idea. The setup is pretty simple;
There's the game loop that takes care of all the usual things: input, collision detection, etc. There's my little ship that can fire bullets. Firing the bullets is easily done but it gets a bit odd with the shooting of the bullets. Right now, I simply have an array of 10 bullets. When the player presses fire, the first bullet not on the screen is selected and fired, by placing it at the top of the ship and then moving it forward. The forward movement is done by a method in the game loop called moveBullet(). With each game loop iteration, regardless of where the 10 bullets are, they simply get 5 pixels added to their Y location and the new position is set for the sprite. This all works like a charm, so there's no question there.
It gets tricky, however, when I would like to introduce an enemy ship. Again, placing the enemy ship isn't the problem. In fact, if I want it to fire whenever the player fires, this too works just fine. I have simply copied the above setup from the player and applied it to the enemy. The thing is, however, that if I want to create a game with different missions (and thus: different amount of enemies per mission), I do not want to run about 10 or 20 moveEnemyBullet() methods in my main game loop. (Especially not when they're not all being used!) I would want something more CPU efficient.
So, my question is: how can I create a way of letting the enemies fire their bullets whenever they feel like it (I'll write AI for that) but let the movement only activate for that enemy iteration when it's needed, instead of running all the time, eating up CPU cycles?

Thanks, doubld!
Funnily enough, I talked this problem over with a friend last night and he suggested nearly the very same thing! Only difference was to place all created bullets in a vector, and then loop through the vector to fire off all the bullets their respective moveBullets method. The reason for that suggestion was because I indicated I wanted to have multiple weapon types but still would like to fire them all through one loop, perhaps each weapon with its own behaviour. (Say: have custom bullets, but also have heatseeking missiles.) He suggested creating an interface called Weapon and have all weapon classes implement this, like so:
public interface Weapon {
     void createWeapon() throws IOException;
     void fireWeapon();
     void moveWeapon();
     void destroyWeapon();
     Sprite getWeaponSprite();
}And then call all the movement methods (or other shared methods) and have different types of weapons all in the same vector, firing off in one game loop, like so:
for(int i=0; i < weaponVector.size(); i++)
     ((Weapon) weaponVector.elementAt(i)).moveWeapon();
}This way, each weapon that's created is in the vector and can be removed once used (as you said: either by hitting the player / enemy or by moving off the screen).
All in all, I think, because or the different behaviours I want per weapon, I'm going with the variant suggested by my friend. However, it's very good to hear two very different people with a technical background give roughly the same advice. That gives me a good idea that I'm on the right way. :)

Similar Messages

  • Mapping/invoking key codes in a GameCanvas's main game loop.

    I'm trying to bind some diagonal sprite movement methods to the keypad. I already know that I have to map out the diagonals to key codes since key states only look out for key presses in the upper half of the phone (d-pad, soft buttons, etc...). Problem is, how do I invoke them in the main game loop since a key state can be encapsulated in a method and piped through the loop? What makes this even worst is a bug that my phone maker's game API (Siemens Game API for MIDP 1.0, which is their own implementation of the MIDP 2.0 Game API) has, in which if I override the keyPressed, keyReleased, or keyRepeated methods, it will always set my key states to zero, thus I can't move the sprite at all. Also, it seems that my phone's emulator automatically maps key states to 2, 4, 6, and 8, so my only concern is how do I map the diagonal methods into 1, 3, 7, and 9, as well as invoking them in the main game loop? Enclosed is the example code that I've been working on as well as the link to a thread in the Siemens (now Benq Mobile) developer's forum about the bug's discovery:
    http://agathonisi.erlm.siemens.de:8080/jive3/thread.jspa?forumID=6&threadID=15784&messageID=57992#57992
    the code:
    import com.siemens.mp.color_game.*;
    import javax.microedition.lcdui.*;
    public class ExampleGameCanvas extends GameCanvas implements Runnable {
    private boolean isPlay; // Game Loop runs when isPlay is true
    private long delay; // To give thread consistency
    private int currentX, currentY; // To hold current position of the 'X'
    private int width; // To hold screen width
    private int height; // To hold screen height
    // Sprites to be used
    private GreenThing playerSprite;
    private Sprite backgroundSprite;
    // Layer Manager
    private LayerManager layerManager;
    // Constructor and initialization
    public ExampleGameCanvas() throws Exception {
    super(true);
    width = getWidth();
    height = getHeight();
    currentX = width / 2;
    currentY = height / 2;
    delay = 20;
    // Load Images to Sprites
    Image playerImage = Image.createImage("/transparent.PNG");
    playerSprite = new GreenThing (playerImage,32,32,width,height);
    playerSprite.startPosition();
    Image backgroundImage = Image.createImage("/background2.PNG");
    backgroundSprite = new Sprite(backgroundImage);
    layerManager = new LayerManager();
    layerManager.append(playerSprite);
    layerManager.append(backgroundSprite);
    // Automatically start thread for game loop
    public void start() {
    isPlay = true;
    Thread t = new Thread(this);
    t.start();
    public void stop() { isPlay = false; }
    // Main Game Loop
    public void run() {
    Graphics g = getGraphics();
    while (isPlay == true) {
    input();
    drawScreen(g);
    try { Thread.sleep(delay); }
    catch (InterruptedException ie) {}
    //diagonalInput(diagonalGameAction);
    // Method to Handle User Inputs
    private void input() {
    int keyStates = getKeyStates();
    //playerSprite.setFrame(0);
    // Left
    if ((keyStates & LEFT_PRESSED) != 0) {
    playerSprite.moveLeft();
    // Right
    if ((keyStates & RIGHT_PRESSED) !=0 ) {
    playerSprite.moveRight();
    // Up
    if ((keyStates & UP_PRESSED) != 0) {
    playerSprite.moveUp();
    // Down
    if ((keyStates & DOWN_PRESSED) !=0) {
    playerSprite.moveDown();
    /*private void diagonalInput(int gameAction){
    //Up-left
    if (gameAction==KEY_NUM1){
    playerSprite.moveUpLeft();
    //Up-Right
    if (gameAction==KEY_NUM3){
    playerSprite.moveUpRight();
    //Down-Left
    if (gameAction==KEY_NUM7){
    playerSprite.moveDownLeft();
    //Down-Right
    if (gameAction==KEY_NUM9){
    playerSprite.moveDownRight();
    /*protected void keyPressed(int keyCode){
    int diagonalGameAction = getGameAction(keyCode);
    switch (diagonalGameAction)
    case GameCanvas.KEY_NUM1:
    if ((diagonalGameAction & KEY_NUM1) !=0)
    playerSprite.moveUpLeft();
    break;
    case GameCanvas.KEY_NUM3:
    if ((diagonalGameAction & KEY_NUM3) !=0)
    playerSprite.moveUpRight();
    break;
    case GameCanvas.KEY_NUM7:
    if ((diagonalGameAction & KEY_NUM7) !=0)
    playerSprite.moveDownLeft();
    break;
    case GameCanvas.KEY_NUM9:
    if ((diagonalGameAction & KEY_NUM9) !=0)
    playerSprite.moveDownRight();
    break;
    repaint();
    // Method to Display Graphics
    private void drawScreen(Graphics g) {
    //g.setColor(0x00C000);
    g.setColor(0xffffff);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(0x0000ff);
    // updating player sprite position
    //playerSprite.setPosition(currentX,currentY);
    // display all layers
    //layerManager.paint(g,0,0);
    layerManager.setViewWindow(0,0,101,80);
    layerManager.paint(g,0,0);
    flushGraphics();
    }EDIT: Also enclosed is a thread over in J2ME.org in which another user reports of the same flaw.
    http://www.j2me.org/yabbse/index.php?board=12;action=display;threadid=5068

    Okay...you lost me...I thought that's what I was doing?
    If you mean try hitTestPoint ala this:
    wally2.addEventListener(Event.ENTER_FRAME, letsSee);
    function letsSee(event:Event)
              // create a for loop to test each array item hitting wally...
              for (var i:Number=0; i<iceiceArray.length; i++)
                   // if you don't hit platform...
              if (wally2.hitTestPoint(iceiceArray[i].x, iceiceArray[i].y, false)) {
              wally2.y -= 5;}
                          return;
    That's not working either.

  • Few questions - game loop, data types, speed

    Hello, I have a few questions after studying some topics in this forum regarding game creation:
    1) What's the fastest way to wait in the game loop? I've seen two approaches:
    thread.sleep(10)andsynchronized(this) { wait(10); }2) What data types shall I use? In C++ I use to prefer int over short in all cases, because 32bit hardware works faster with integers. Is this same on cell phones?
    3) Speed of applications is slow. I just wonder wheter it's my fault. I was testing application, which only cleared the buffer and outputted FPS and I got around 20 frames. It was Nokia 6300 with 240x320 display. After testing on other phones I've found out that the bigger the resolution, the slower the game is going. Is this normal?
    Thanks for replies...

    1) You're not going to notice any really speed difference between the two code snippets. Read up on 'Threads', and you'll see why one may be used in place of the other depending on the situation. In general there may be a slight performance loss, however unnoticable, when using the synchronized version, but when you are multithreading it is likely necessary.
    sleep(int) is impossible to interrupt, so it's generally a no-no in most situations. However we are talking about devices where every bit of performance helps, so as long as it works for ya, it's not a big deal.
    2) The performance difference is fairly negligable, if any. The biggest thing to consider is memory requirements, and shorts take 1/2 the data.
    Also, many phones don't support floating point data types, so you'll likely need to use ints/longs to calculate your values if you want to have any accuracy beyond whole numbers. Doing something like shifting bits or using 1000x values in your calculations can get around most of the problems when you can't use floats.
    3) The biggest performance killers are IO, memory allocation, screen drawing; pretty much in that order. So I imagine that you are re-creating a new String object every time you output your FPS value on screen right? Doing that every frame would destroy any hopes of getting high-performance.
    Just be careful, and never allocate objects when you can avoid it. anything where you concat String objects using + will cause your performance to die a horrible painful slow death. Remove anything that says 'new' from your main loop, and all String operations, and it'll likely speed things up a lot for ya.
    Does your main loop have something like this?
    g.drawString("FPS: " + currentFps, 0,0,Graphics.TOP | Graphics.LEFT);
    This is very bad because of the String operation. It'll create a new String every frame.
    If you have any more specicif questions, or you'd just like to pick the brain of a mobile game dev, stop by my messageboard:
    http://attackgames.proboards84.com
    Message was edited by:
    hooble

  • Restart logic and looping logic in process flow

    Is there any restart logic and looping logic in Oracle Warehouse Builder, process flow?

    Hi,
    The answer is NO. The curent version does not have restartable functionality. You have to have your own design for this.
    ta
    mahesh

  • FUNCTION Cursor / WHILE LOOP vs LOOP / Logic help (RESOLVED)

    (I HAVE RESOLVED - making it more efficient, I hope - see FUNCTION) if anyone has a different =, more efficient way to write this, please share...
    I need help with a Function:
    I am trying to get a handle on a rate. This table has and employee column this is usually populated with 'ALL'. On the off chance that it has an actual employee number, I want that rate; otherwise, the rate with ALL. Everything in both records will be the same except the employee field. (if there happens to be an ALL rate and an individual employee rate. Usually there will only be one record).
    As I started to write this, I tested the WHILE loop logic and did not get a value back, but when I test a simple loop, I do. I have not finished the entire logic only getting a handle on a record that has the employee.
    I would like help:
    Understanding why WHILE loop isn't working
    How to go about testing if CURSOR c_job_payroll_rate_emp FOUND - get this value and EXIT otherwise IF NOT FOUND then get value from c_job_payroll_rate_all
    Start to my function is below w/ testing comments(** THIS IS THE RESOLVED FUNCTION.
    FUNCTION job_pay_rate(in_comp_code IN jobpayrate.jpr_comp_code%TYPE,
                        in_job_code IN jobpayrate.jpr_job_code%TYPE,
                             in_phs_code IN jobpayrate.jpr_phs_code%TYPE,
                                  in_cat_code IN jobpayrate.jpr_cat_code%TYPE,
                                  in_trd_code IN jobpayrate.jpr_trd_code%TYPE,
                                  in_emp_code IN jobpayrate.jpr_emp_no%TYPE)
    RETURN jobpayrate.jpr_billing_rate%TYPE
    IS
    v_val jobpayrate.jpr_billing_rate%TYPE;
    CURSOR c_job_payroll_rate_all IS     
         SELECT max(jpr_billing_rate) rate
         FROM jobpayrate
    WHERE jpr_comp_code = in_comp_code
         AND jpr_job_code = in_job_code
         AND jpr_trd_code = in_trd_code      
         AND jpr_phs_code = in_phs_code
         AND jpr_cat_code = in_cat_code
         AND jpr_emp_no <> in_emp_code;     
    CURSOR c_job_payroll_rate_emp IS     
         SELECT max(jpr_billing_rate) rate
         FROM jobpayrate
    WHERE jpr_comp_code = in_comp_code
         AND jpr_job_code = in_job_code
         AND jpr_trd_code = in_trd_code
         AND jpr_phs_code = in_phs_code
         AND jpr_cat_code = in_cat_code
         AND jpr_emp_no = in_emp_code;     
    BEGIN
    FOR rec_e IN c_job_payroll_rate_emp LOOP
    v_val := rec_e.rate;
    IF rec_e.rate IS NULL THEN
    FOR rec_a IN c_job_payroll_rate_all LOOP
    v_val := rec_a.rate;
    END LOOP;
    END IF;
    END LOOP;
    RETURN v_val;
    END job_pay_rate;
    Message was edited by:
    KB

    Rather than using cursors for zero or 1 row queries, use SELECT ... INTO
    Untested
    FUNCTION job_pay_rate(in_comp_code IN jobpayrate.jpr_comp_code%TYPE,
    in_job_code IN jobpayrate.jpr_job_code%TYPE,
    in_phs_code IN jobpayrate.jpr_phs_code%TYPE,
    in_cat_code IN jobpayrate.jpr_cat_code%TYPE,
    in_trd_code IN jobpayrate.jpr_trd_code%TYPE,
    in_emp_code IN jobpayrate.jpr_emp_no%TYPE)
    RETURN jobpayrate.jpr_billing_rate%TYPE
    IS
    v_val jobpayrate.jpr_billing_rate%TYPE;
    BEGIN
    SELECT max(jpr_billing_rate) rate INTO v_val
    FROM jobpayrate
    WHERE jpr_comp_code = in_comp_code
    AND jpr_job_code = in_job_code
    AND jpr_trd_code = in_trd_code
    AND jpr_phs_code = in_phs_code
    AND jpr_cat_code = in_cat_code
    AND jpr_emp_no = in_emp_code;
    RETURN v_val;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        SELECT max(jpr_billing_rate) rate INTO v_val
        FROM jobpayrate
        WHERE jpr_comp_code = in_comp_code
        AND jpr_job_code = in_job_code
        AND jpr_trd_code = in_trd_code
        AND jpr_phs_code = in_phs_code
        AND jpr_cat_code = in_cat_code
        AND jpr_emp_no <> in_emp_code;
        RETURN v_val;
    --OTHER EXCEPTION HANDLING
    END;

  • Game loop using Swing?

    Hey everyone. My simple game engine currently uses Swing for the frames and components, but uses an AWT Canvas for the actual game display. I'm trying to figure out how to change entirely to Swing components.
    Here's basically how I've laid out my game loop thread using Canvas:
    1. Do calculations since last loop
    2. Get Graphics2D object via the canvas' BufferStrategy object
    3. Clear the background with white.
    4. Call the draw(Graphics2D) method.
    5. Dispose & flip the buffer.
    6. Call the update(long) method using the calculations from step 1.
    7. Sleep for a bit.
    8. Repeat loopThis is working very smoothly right now and is very flexible for subclassing. But since it's a mix of Swing & AWT there are some problems here and there and I feel it could be improved by keeping it Swing-only.
    What's the best way to implement a similar game thread loop using a Swing component?
    Code can be supplied if needed. Thanks!

    Use a JPanel instead of a Canvas.

  • Game loop

    I can move an image with a mouse and use a class to load the image .
    It works.
    q1)how do i put this code in a game loop in .fla file as I need to move objects automatically? Do I use a timer or is there something better?
    q2) How do I declare an event when the image from the class ClassImg2 has been loaded? I need to know this in the .fla file.
    .fla file below
    var li:ClassImg2= new ClassImg2("ladybug.png",120,120);
    addChild(li);
    stage.addEventListener(KeyboardEvent.KEY_DOWN,doSomething);
    function doSomething(e:KeyboardEvent):void
      if (e.keyCode==37) //39 is right arrow
      trace("left pressed")
      li.moveleft();
      if (e.keyCode==39) //39 is right arrow
      trace("right pressed")
      li.moveright();

    q1) the game loop works but the movement of the image with the mouse  is too fast.
    I changed the framerate to 4 in the timeline and only move the image  1 per frame when i press right/arrow key.
    How can I slow this down?
    var li:ClassImg2= new ClassImg2("ladybug.png",120,120);
    addChild(li);
    stage.addEventListener(Event.ENTER_FRAME, gameLoop);
    function gameLoop(event:Event)
    stage.addEventListener(KeyboardEvent.KEY_DOWN,doSomething);
    function doSomething(e:KeyboardEvent):void
      if (e.keyCode==37) //39 is right arrow
      trace("left pressed")
      li.moveleft();
      if (e.keyCode==39) //39 is right arrow
      trace("right pressed")
      li.moveright();
    UPDATE- I take the key events out of the game loop and it works

  • My game loop

    My game loop works and I want someone to look
    at it to see if I can improve it AS3 style.
    What I do is load an image from a
    class and it dispatches an event when completed. When all images are loaded
    (which is 1 in this example) I then start the game loop which is just a
    trace.
    This way I could load many images and then start the my game loop
    This is a skeleton I can build upon.
    var noLoaded:int;
    noLoaded=0
    var li:ClassImg2= new ClassImg2("ladybug.png",120,120);
    li.addEventListener("image_loaded",imageLoadedHandler);
    addChild(li);
    function imageLoadedHandler(e:Event){
         stage.addEventListener(KeyboardEvent.KEY_DOWN,doSomething);
      noLoaded+=1
    function doSomething(e:KeyboardEvent):void
              if (e.keyCode==37) //39 is right arrow
              trace("left pressed")
              li.moveleft();
              if (e.keyCode==39) //39 is right arrow
              trace("right pressed")
              li.moveright();
    stage.addEventListener(Event.ENTER_FRAME, gameLoop);
    function gameLoop(event:Event)
         if (noLoaded==1)
              trace("all loaded");     

    you shouldn't start your loop etc until everything's loaded:
    var noLoaded:uint=0;
    var totalToLoad:uint=1;
    var li:ClassImg2= new ClassImg2("ladybug.png",120,120);
    li.addEventListener("image_loaded",imageLoadedHandler);
    addChild(li);
    function imageLoadedHandler(e:Event){
          noLoaded+=1;
    if(noLoaded==totalToLoad){
    stage.addEventListener(KeyboardEvent.KEY_DOWN,doSomething);
    stage.addEventListener(Event.ENTER_FRAME, gameLoop);
    function doSomething(e:KeyboardEvent):void
              if (e.keyCode==37) //39 is right arrow
              trace("left pressed")
              li.moveleft();
              if (e.keyCode==39) //39 is right arrow
              trace("right pressed")
              li.moveright();
           function gameLoop(event:Event)
                  trace("all loaded");    

  • Is there any way to have a COMPLETE list of all samples and loops ( Logic 8

    I'm sure it's been posted previously, but anyway, I'm looking to buy new Apple Loops libraries and I have faced the fact , that many of the sounds and loops produced by third parties manufacturers have been already included in Logic installation discs.
    I have a list of Apple Loops DVD's that have been included with Logic somewhere, the problem is, Apple didn't post ( I believe) the credits of all 3rd party manufacturers that have produced these libraries that are included with Logic or Garage band. Is there any way to have a COMPLETE list of all samples and loops that are included with Apple DAW's so I wouldn't duplicate anything ? I'm pretty much positive that Apple had other companies to sound design and sample all libraries for them, so is there also a way to have a list of those manufacturers? Again, the objection is to start upgrading the sound library without any possible duplication?
    Thanks in advance!

    Chris, I certainly don't mind additional questions and postings.
    I believe there are many issues with Apple Loops and Logic that need to be resolved and people need to be aware of that. Unfortunately, in opposite to the old "german" version of Logic , there's no lifetime tech support, you can't even call and ask the question after 60 days , which isn't right for a professional software of this level, especially considering the fact that many things still remain vague in Logic even for developers and tech support people!( believe me, I've called and asked!)
    Issues like that need to be resolved over the phone with the company, period!
    One thing I also learned over the years as a Mac OSX user, if something doesn't work, don't mess with it. Delete your drive and re-install everything. This is very frustrating , I know, but unfortunately this is the only way to deal with OSX issues, if you got a problem with your system, don't try to fix it. It's never gonna be the same again. I know , it's off the topic a little bit, but if your content is missing from the system files, before installing your new Logic, back up your important files, wipe up your drive and clean install Mac OSX , run updates and then install the Logic. Most likely , everything will be in it's place, at least 90% or more. I gave up trying to make two system in my house to be compatible 100% , but it's OK if they're 90% or more identical. I spent enormous amount of time trying to find out what's missing and where, I visited most of the forums and there's no clean answer.
    Message was edited by: Moderator

  • Problem with looping logic

    Hello all,
    Ok reposted using code tags, sorry about that.
    I'm trying to write some code to take in a 2D int array, loop through the array to identify where certain blocks of numbers begin and record that location so that I an jump straight to it at a later time. The number blocks go up iteratively from a point from 0 to 9 and are surrounded by nodata values(-9999).
    The problem is that when I print out the numbers they are only being recognised up to 6 (7th number) and when I check the locations against the original text file they dont match. I think it's just a problem with my logic but I'm not sure why.
    The text file is converted to ints and placed in an array from a buffered file reader in a seperate class. I can put this up if needed.
    Any help would be much appreciated.
    Thanks.
    Duncan
    *  Class imports text file which contains a collection of values, either nodata(-9999) or a location
    *  represented by numbers moving away from a point; 0 closest then 1, then 2 etc.
    *  records the first location of each number to avoid having to loop through the whole file each time.
    *  i.e. can later jump straight to the first recorded location of each number.
    *  In current text file there are 10 numbers(0 - 9) but for some reason it stops finding them after
    *  6(seventh no.) and having checked the location values against the original text file these are wrong
    *  by a fair way as well.
    import java.io.*;
    //import java.awt.*;
    //import java.awt.event.*;
    public class Hydrograph {
         int width = 0;
         int height = 0;
         int dZeroC, dZeroD = 0;
         int dOneC, dOneD = 0;
         int dTwoC, dTwoD = 0;
         int dThreeC, dThreeD = 0;
         int dFourC, dFourD = 0;
         int dFiveC, dFiveD = 0;
         int dSixC, dSixD = 0;
         int dSevenC, dSevenD = 0;
         int dEightC, dEightD = 0;
         int dNineC, dNineD = 0;
         public Hydrograph() {
              /* Ignore this bit it's being used for something else
              //File file = new File("c:/Users/Duncan/Documents/MODULES/MSc Dissertation/Code/A1.txt");
              //File file = new File("M:/java/code/A1.txt");
              ArrayRead ar = null;
              ar = new ArrayRead(file);
              int rows = ar.getRows();
              int columns = ar.getColumns();
              int steps = ar.getSteps();
              int[][][] threeDIntArray = ar.getThreeDIntArray();
              // Creates a new instance of delay class which takes in a text file and converts
              // it to int form, placing it into a 2D int array.
              Delay dLay = null;
              dLay = new Delay();
              width = dLay.getWidth();
              height = dLay.getHeight();
              int[][] twoDDelayFile = dLay.getTwoDintArray();
              int delayCount = 0;
              // Loops through 2D int array to identify when number first equals 0, then passes
              // the height and width values to storeDelayPos method below. Then finds for 1, 2
              // 3, 4,...etc by adding 1 to delayCount.
              System.out.println(" ");
              for (int a=0; a<width; a++) {
                   for (int b=0; b<height; b++) {
                        if (twoDDelayFile[a] == delayCount) {
                             int c, d = 0;
                             c = a;
                             d = b;
                             storeDelayPos(c, d, delayCount);
                             System.out.println(delayCount);
                             delayCount++;
                             break;
                   //System.out.println(" ");
              System.out.println(" ");
              System.out.print(dZeroC + " " + dZeroD);
              System.out.println(" ");
              System.out.print(dOneC + " " + dOneD);
              System.out.println(" ");
              System.out.print(dTwoC + " " + dTwoD);
              System.out.println(" ");
              System.out.print(dThreeC + " " + dThreeD);
              System.out.println(" ");
              System.out.print(dFourC + " " + dFourD);
              System.out.println(" ");
              System.out.print(dFiveC + " " + dFiveD);
              System.out.println(" ");
              System.out.print(dSixC + " " + dSixD);
              System.out.println(" ");
              System.out.print(dSevenC + " " + dSevenD);
         // Takes in width, height and delayCount value and sets variables according to
         // the value of delayCount.
         void storeDelayPos (int setC, int setD, int setDCount) {
              int dCount = 0;
              dCount = setDCount;
              switch(dCount) {
                   case 0:
                        dZeroC = setC;
                        dZeroD = setD;
                        break;
                   case 1:
                        dOneC = setC;
                        dOneD = setD;
                        break;
                   case 2:
                        dTwoC = setC;
                        dTwoD = setD;
                        break;
                   case 3:
                        dThreeC = setC;
                        dThreeD = setD;
                        break;
                   case 4:
                        dFourC = setC;
                        dFourD = setD;
                        break;
                   case 5:
                        dFiveC = setC;
                        dFiveD = setD;
                        break;
                   case 6:
                        dSixC = setC;
                        dSixD = setD;
                        break;
                   case 7:
                        dSevenC = setC;
                        dSevenD = setD;
                        break;
                   case 8:
                        dEightC = setC;
                        dEightD = setD;
                        break;
                   case 9:
                        dNineC = setC;
                        dNineD = setD;
                        break;
                   default:
                        System.out.println("OUT OF BOUNDS");
                        break;
         public static void main (String args[]) {
         new Hydrograph();

    Hi,
    I am working on a hydrograph program in java as well... I am trying to represent rainfall data. Do you think that you could share some of the code that you came up with, so that I don't have to go through the whole process.
    thank you so much,
    Kevin

  • Tidal Looping Logic

    Hi, 
    I am new tidal. I have a scenario. 
    I need to loop through 10 databases for given set of tables ..say 1.
    I have created table A which has entry for each of the tables and the databases , so total 10 records.
    I have a ETL job for each table. I am planning to create a file trigger at the beginning of Tidal job step and then select top first record from table A run the ETL job first database. 
    I need tidal to keep running this job till file trigger is available. Once I am done with all 10 databases, I will delete the trigger file thus finishing the Tidal job run. 
    In theory, it should work. I am not sure if this will work in Tidal. If not what are my other option ?
    Thanks
    AB

    You don't specify how you're syncing them. If it's just MIDI clock, the MPC is probably just sending clock info, and not the necessary commands to jump backward in time for looping, hence Logic doesn't cycle.
    Try syncing them via MTC if the MPC supports it.
    If you can't do that, you could try putting Logic into cycle mode to see if Logic itself will loop while syncing to MIDI clock.

  • Nested for loop logic

    I am trying to create a triangle with for loop. i wrote this codepublic class Test {
        public static void main(String[] args) {
            for(int x = 1; x <= 6; x++) {
                for(int y = 1; y <= (x*2-1); y++) {
                    System.out.print("x");
               System.out.println("");
    }and i got answer like this
    x
    xxx
    xxxxx
    xxxxxxx
    xxxxxxxxx
    xxxxxxxxxxx
    but what i am trying to do is that will strat showing the results from the middle.
    ___X___
    __XXX__
    something like that. Need some explaination or hint what i am missing. (underscores are not part of my program:))
    thanks

    So since the spaces look right now, lets step through the plus loop
    for(k = i; k <= i*2-1; k++)
                    System.out.print("+"); First time starting to go through the loop i is 0.
    So 0 is not <= -1 [0*2-1 = -1] so no pluses get printed on the first time through.
    the second time starting to go through the loop i is 1.
    So first time through 1 is <= 1 [1*2-1 = 1] so print a +.
    Second time through 2 is not <= 1, so we end with just one +.
    The third time starting the loop i is 2.
    So first time through 2 is <= 3 [2*2-1 = 3] so print a +.
    Second time through 3 is <= 3 so print another +.
    Third time through 4 is not <= 3 so we end with just two +s.
    Uh oh, we wanted three s not two s, where did we go wrong? Let's try one more and see if we can see it.
    The fourth time starting i is 3.
    So first time through 3 is <= 5 [3*2-1 = 5] so print a +.
    Second time through 4 is <= 5 so print another +.
    Third time through 5 is <= 5 so print another +.
    Fourth time through 6 is not <= 5 so we end with just three +s.
    Now we have a choice, we can get mad and start throwing stuff and screaming at the stupid computer for doing it all wrong, or we can realize the problem is somewhere in the code and we can find it and fix it.
    What do you think?
    JSG
    EDIT: Note: you actually have two problems displayed here, both should be obvious but one is slightly hidden in the output until you fix the other. Both should have made themselves clear if you had done a simple step through yourself. As i demonstrated it is really easy to do and something you better get real good at if you want to be a good programmer.
    Edited by: JustSomeGuy on Nov 24, 2008 11:22 AM

  • Help with  looping logic

    1. I am new to this forum, can someone let me know how I attach a code tag.
    2. Im doing an exercise where I have to enter 20 values into an array . Each value I enter has to be different from a value previously entered value.If the value already exists in the array, the program should allow the user to put in a another value. I have been trying nested for loops but im just confused. Can someone help me on how to go about it ?

    1. I am new to this forum, can someone let me know
    how I attach a code tag.http://forum.java.sun.com/help.jspa?sec=formatting
    2. Im doing an exercise where I have to enter 20
    values into an array . Each value I enter has to be
    different from a value previously entered value.If
    the value already exists in the array, the program
    should allow the user to put in a another value. I
    have been trying nested for loops but im just
    confused. Can someone help me on how to go about it ?for (loop twenty times)
    ask user for value
    while (value is in the array) ask user for new value
    insert value into array
    next

  • Game main loop using Thread. How to ?

    Hello !
    Is anybody know what happened with threads, which was created by MIDLet when MIDLet will be closed ?
    More details: i design a specific game engine for MIDP2.0. In many available resources main game loop implemented through separate Thread, but one thing is just missed - how to correctly stop this thread when player want to exit from game ? Mostly all examples just call notifyDestroyed() and do nothing more. But I think what it is wrong program behaviour. So I have questions to advanced MIDP programmers:
    1) Do we need correctly stop all Threads before call notifyDestroyed() or can just forget about it ? (I think need to stop all threads ...). Maybe some documentation or usefull link is available about this or related problem ?
    Where get documentation about Threads in Java, and how to VM stop thread during garbage collection. As I think exactly G&#1057; will destroy MEDLet threads if I don't stop it manually ?

    ... But I think that all created threads should be
    killed in logical right place. For example, if thread
    is using for animation and created in Canvas object,
    this thread should be killed before killing Canvas
    object (for example command "Exit" have been choosen,
    firstly we kill thread, secondly we call destroyApp )
    If midlet uses user interface, I never called
    notifyDestroyed() from my own created thread, because
    application usually should be finished when command is
    choosen or some key pressed.I completely agree with both notes, and even think what I was wrong in general - when decide to use main loop paradigm in PC way (strictly speaking I just copy paradigm from PC project). You give me an good idea - use custom-purpose threads instead general-purpose "main-loop" thread. I just will look on this thread from other point of view and use it only for call update() for my canvas and provide way to handle time-depended actions (say for animation). No anything more. So all I will need - proper synchronization when perform time-depended action.
    So I can stop that thread from destroyApp() when AMS want to destroy my MIDlet, and I can stop that thread from any event-handler in my canvas (in command handler or just key-pressing handler) and then call notifyDestroyed() in order to stop MIDLet manually. So no more calling notifyDestroyed() from any MIDlet-own threads. What you think ?
    Just for intresting - citation from JVM Specification:
    2.16.9 Virtual Machine Exit
    A Java Virtual Machine terminates all its activity and exits when one of two things happens:
    * All the threads that are not daemon threads (�2.17) terminate.
    In CLDC specification no any changes in this paragraph was made, so we can say what if we does not stop all threads which we create in MIDlet the MIDLet execution will be endless ? It is intresting - implementation JVM in real device start JVM for each MIDLet or start JVM once and start MIDlets in this one-session JVM ? In first-case it is possible to just stop JVM (with all threads) and release any resources (looks little dirty, but why not ?) in second-case all "zombie" threads can live endless (until device switch off) and just decrease performance and eat resources ...
    Need more specification ...
    Many thanks to RussianDonz for collaboration.

  • How does it work...LOOP,..ENDLOOP logic

    I just tried the script below to understand the loop logic.
    FIX ("Person","Jan")
    var c=0;
    LOOP(2)
    "wage"
    c=c+1;
    c;
    ENDLOOP
    ENDFIX
    I expected that the result of the calculation would be wage = 2 but instead I found wage = 10.
    I tried this with LOOP(2) too and the result was wage = 19.
    it is like when loop = 1 c= 1
    when loop = 2 c= 10
    when loop = 3 c= 19
    I am completely lost in LOOP logic. How does this logic work.

    one question regarding your answer.,
    I have these dimesions : company , costcenter , person , period.
    company has comp1 , comp2 members
    costcenter has cc1 , cc2 members
    person has p1 , p2 members
    period as usual.
    I have only two data blocks which are ; comp1->cc1->p1->begbalance and comp1->cc1->p2->begbalance
    I dont have any data for comp2 or cc2.
    And my whole script as below.When I check the app.log I see the script created data for comp2 and cc2 aswell.
    But in the script I didnt even used "SET CREATENONMISSINGBLK ON".is this typical for essbase.
    I even tried "SET CREATENONMISSINGBLK OFF" nothing changed.
    So how can I manage my script to work for only existing data.
    FIX(@RELATIVE ("company",0),@RELATIVE ("costcenter",0),@RELATIVE ("person",0))
    FIX ("jan")
    SET MSG DETAIL;
    LOOP(1)
    "wage"
    c=c+1;
    c;
    ENDLOOP
    ENDFIX
    ENDFIX
    ENDFIX
    ENDFIX

Maybe you are looking for