seanlego23 wrote:
Is it possible to have a pointer array that holds a string be initialized to a variable?
Example:
const char* c[] = "< Chicago >";
[...]
char* citystring;
[...]
citystring = c;

So far, it hasn't worked for me. Anyone know any solution?

Do you mean like this:

Code:
const char* c[] = {"< Chicago >"}; //pointer array that holds a string
[...]
char citystring[15]; //variable
[...]
strcpy(citystring, c[0]); //initialize pointer array that holds a string to variable
Rico wrote:
seanlego23 wrote:
Is it possible to have a pointer array that holds a string be initialized to a variable?
Example:
const char* c[] = "< Chicago >";
[...]
char* citystring;
[...]
citystring = c;

So far, it hasn't worked for me. Anyone know any solution?

Do you mean like this:

Code:
const char* c[] = {"< Chicago >"}; //pointer array that holds a string
[...]
char citystring[15]; //variable
[...]
strcpy(citystring, c[0]); //initialize pointer array that holds a string to variable

Yes, that works thanks. However, your code that you suggested earlier, still did not work. I am not educated nor experienced enough to know why, so I moved back to my earlier code. Still have the os_GetCSC() registering problem. If anyone knows any solutions, post them please. Otherwise, I will continue to go further with the program. Smile

Edit:
Nevermind. If I use the keypadc library for the end of loop check, it works perfectly fine. For some reason, since I use kb_2nd, if I just input the command kb_Graph; before the second kb_2nd check, it works. (As described above, that's how I fixed the double kb_ScanGroup() for different functions, for clarification).

New Problem:
I know people say not to use a goto. But I did. And it works. To a point. If I click on settings, and change whatever, it will take me back to the home screen. Problem being, once I click a button, it exits the program. So does anyone know any way to jump back to the home screen after I'm done in settings?
Thanks to Rico, the problem is solved. The goto works fine. Now on to the main game programming.
I decided to split the program up into multiple .c files again. This time it works, but I get a bunch of warnings that a bunch of things are already externally defined.

My external variables are all globally defined in main.c outside of the function.
The variables are (extern) defined inside the functions they are used in. (A C tutorial reccomended this to me)

The things that keep saying externally defined is when I repeat #include "", with my own headers, and with graphx.h. It keeps saying gfx_Palette and gfx_vram are already externally defined in all the places I include it. It also says "Segment overlap occurs while binding the segment". I never use either of these two, I haven't messed around with the library, the game still works completely fine with no errors, just a bit slow.

I did notice however, that in the graphx header, the two lines where gfx_palette and gfx_vram are defined, it's underlined in the error color, saying "unexpected token '_At'". Does anyone understand why this is happening?
I added some final settings that customizes the game a bit more. And It doesn't work so well. When I click 'right' or 'left' for the first time after clicking 'up' or 'down' or vise versa, it goes the direction of the key I clicked last first then it will be basically 1 keypress behind. In the gif below, the keypress delay is gone, I fixed that already and it is no longer in the code also posted below.




Code:
void settings() {
    extern uint8_t key;
    extern uint8_t startcity;
    extern long cursor_y;
    extern long cursor_x;
    extern double mfm;
    extern double lfm;
    extern double lom;
    extern double cc;
    int i=1, j=2, k=3, l=6;    //each int is for the same array, but for different aspects

    startcity = chicago;
    strcpy(cityString, c[0]);
    cursor_x = 10;
    cursor_y = 10;
    do {
        gfx_SetDraw(gfx_buffer);
        gfx_FillScreen(0x80);
        gfx_PrintStringXY(">", cursor_x, cursor_y);
        gfx_PrintStringXY("Start City:", 20, 10);
        gfx_PrintStringXY(cityString, 100, 10);
        gfx_PrintStringXY(lomc, 20, 20);                //less than 100 miles
        gfx_PrintStringXY(mppc[i], 100, 20);            //amount
        gfx_PrintStringXY(lfmc, 20, 30);                //less than 500 miles
        gfx_PrintStringXY(mppc[j], 100, 30);            //amount
        gfx_PrintStringXY(mfmc, 20, 40);                //more than 500 miles
        gfx_PrintStringXY(mppc[k], 100, 40);            //amount
        gfx_PrintStringXY(ccc, 20, 50);                 //cargo charge per 1000 lbs
        gfx_PrintStringXY(mppc[l], 150, 50);            //amount
        gfx_PrintStringXY("Back", 20, 60);

        key = os_GetCSC();
        switch (key) {
        case 4:     //up
            switch (cursor_y) {
            case 10:
                cursor_y = 60;
                break;
            default:
                cursor_y -= 10;
                break;
            }
            gfx_SwapDraw();
            break;
        case 1:     //down
            switch (cursor_y) {
            case 60:
                cursor_y = 10;
                break;
            default:
                cursor_y += 10;
                break;
            }
            gfx_SwapDraw();
            break;
        }

        switch (cursor_y) {
        case 10:
            switch (key) {
            case 2:         //left
                switch (startcity) {
                case chicago:
                    strcpy(cityString, b[0]);
                    startcity ^= (boston | chicago);
                    break;
                case NYC:
                    strcpy(cityString, c[0]);
                    startcity ^= (chicago | NYC);
                    break;
                case stLouis:
                    strcpy(cityString, n[0]);
                    startcity ^= (NYC | stLouis);
                    break;
                case boston:
                    strcpy(cityString, s[0]);
                    startcity ^= (stLouis | boston);
                    break;
                }
                gfx_SwapDraw();
                break;
            case 3:         //right
                switch (startcity) {
                case chicago:
                    strcpy(cityString, n[0]);
                    startcity ^= (NYC | chicago);
                    break;
                case NYC:
                    strcpy(cityString, s[0]);
                    startcity ^= (stLouis | NYC);
                    break;
                case stLouis:
                    strcpy(cityString, b[0]);
                    startcity ^= (boston | stLouis);
                    break;
                case boston:
                    strcpy(cityString, c[0]);
                    startcity ^= (chicago | boston);
                    break;
                }
                gfx_SwapDraw();
                break;
            default:
                gfx_SwapDraw();
                break;
            }
            break;
        case 20:
            switch (key) {
            case 2:     //left
                switch (i) {
                case 0:
                    i=6;
                    break;
                default:
                    --i;
                    break;
                }
                gfx_SwapDraw();
                break;
            case 3:     //right
                switch (i) {
                case 6:
                    i=0;
                    break;
                default:
                    ++i;
                    break;
                }
                gfx_SwapDraw();
                break;
            }
            break;
        case 30:
            switch (key) {
            case 2:     //left
                switch (j) {
                case 0:
                    j=6;
                    break;
                default:
                    --j;
                    break;
                }
                gfx_SwapDraw();
                break;
            case 3:     //right
                switch (j) {
                case 6:
                    j=0;
                    break;
                default:
                    ++j;
                    break;
                }
                gfx_SwapDraw();
                break;
            }
            break;
        case 40:
            switch (key) {
            case 2:     //left
                switch (k) {
                case 0:
                    k=6;
                    break;
                default:
                    --k;
                    break;
                }
                gfx_SwapDraw();
                break;
            case 3:     //right
                switch (k) {
                case 6:
                    k=0;
                    break;
                default:
                    ++k;
                    break;
                }
                gfx_SwapDraw();
                break;
            }
            break;
        case 50:
            switch (key) {
            case 2:     //left
                switch (l) {
                case 0:
                    l=6;
                    break;
                default:
                    --l;
                    break;
                }
                gfx_SwapDraw();
                break;
            case 3:     //right
                switch (l) {
                case 6:
                    l=0;
                    break;
                default:
                    ++l;
                    break;
                }
                gfx_SwapDraw();
                break;
            }
            break;
        }
    } while (kb_ScanGroup(kb_group_1) != kb_2nd);
    lom = mpp[i];
    lfm = mpp[j];
    mfm = mpp[k];
    cc = mpp[l];
}

Help.
You are swapping the buffer with the screen directly after you press a key and drawing everything to the buffer after that, so the new screen that you want to display is in the buffer. You have to swap the buffer with the screen after you draw everything instead of before, like you are doing.

Code:
   {your code..}
   key = 1;
   gfx_SetDraw(gfx_buffer);
   do {
      if(key) {
         gfx_FillScreen(0x80);
         gfx_PrintStringXY(">", cursor_x, cursor_y);
         gfx_PrintStringXY("Start City:", 20, 10);
         gfx_PrintStringXY(cityString, 100, 10);
         gfx_PrintStringXY(lomc, 20, 20);                //less than 100 miles(161 kilometer)
         gfx_PrintStringXY(mppc[i], 100, 20);            //amount
         gfx_PrintStringXY(lfmc, 20, 30);                //less than 500 miles(161 kilometer)
         gfx_PrintStringXY(mppc[j], 100, 30);            //amount
         gfx_PrintStringXY(mfmc, 20, 40);                //more than 500 miles(161 kilometer)
         gfx_PrintStringXY(mppc[k], 100, 40);            //amount
         gfx_PrintStringXY(ccc, 20, 50);                 //cargo charge per 1000 lbs(453 kilogram)
         gfx_PrintStringXY(mppc[l], 150, 50);            //amount
         gfx_PrintStringXY("Back", 20, 60);
         gfx_SwapDraw();
      }
      {your code..}
Rico wrote:
You are swapping the buffer with the screen directly after you press a key and drawing everything to the buffer after that, so the new screen that you want to display is in the buffer. You have to swap the buffer with the screen after you draw everything instead of before, like you are doing.

Code:
   {your code..}
   key = 1;
   gfx_SetDraw(gfx_buffer);
   do {
      if(key) {
         gfx_FillScreen(0x80);
         gfx_PrintStringXY(">", cursor_x, cursor_y);
         gfx_PrintStringXY("Start City:", 20, 10);
         gfx_PrintStringXY(cityString, 100, 10);
         gfx_PrintStringXY(lomc, 20, 20);                //less than 100 miles(161 kilometer)
         gfx_PrintStringXY(mppc[i], 100, 20);            //amount
         gfx_PrintStringXY(lfmc, 20, 30);                //less than 500 miles(161 kilometer)
         gfx_PrintStringXY(mppc[j], 100, 30);            //amount
         gfx_PrintStringXY(mfmc, 20, 40);                //more than 500 miles(161 kilometer)
         gfx_PrintStringXY(mppc[k], 100, 40);            //amount
         gfx_PrintStringXY(ccc, 20, 50);                 //cargo charge per 1000 lbs(453 kilogram)
         gfx_PrintStringXY(mppc[l], 150, 50);            //amount
         gfx_PrintStringXY("Back", 20, 60);
         gfx_SwapDraw();
      }
      {your code..}

That works. Thanks.
New Problem:
I click up in the settings over and over. It works. I click left and right and it works. But if I click the down button and the cursor_y is going from 20 to 30, CEmu RAM Clears.


Code:
void settings() {
    extern uint8_t key;
    extern uint8_t startcity;
    extern long cursor_y;
    extern long cursor_x;
    extern double mfm;
    extern double lfm;
    extern double lom;
    extern double cc;
    int i=1,j=2,k=3,l=6;//each int is for the same array, but for different aspects

    startcity = chicago;
    strcpy(cityString, c[0]);
    cursor_x = 10;
    cursor_y = 10;
    key = 1;
    gfx_SetDraw(gfx_buffer);
    do {
        if(key) {
            while (kb_AnyKey());
            gfx_FillScreen(0x80);
            gfx_PrintStringXY(">", cursor_x, cursor_y);
            gfx_PrintStringXY("Start City:", 20, 10);
            gfx_PrintStringXY(cityString, 100, 10);
            gfx_PrintStringXY(lomc, 20, 20);                //less than 100 miles(161 kilometer)
            gfx_PrintStringXY(mppc[i], 100, 20);            //amount
            gfx_PrintStringXY(lfmc, 20, 30);                //less than 500 miles(161 kilometer)
            gfx_PrintStringXY(mppc[j], 100, 30);            //amount
            gfx_PrintStringXY(mfmc, 20, 40);                //more than 500 miles(161 kilometer)
            gfx_PrintStringXY(mppc[k], 100, 40);            //amount
            gfx_PrintStringXY(ccc, 20, 50);                 //cargo charge per 1000 lbs(453 kilogram)
            gfx_PrintStringXY(mppc[l], 150, 50);            //amount
            gfx_PrintStringXY("Back", 20, 60);
            gfx_SwapDraw();
        }


        key = os_GetCSC();
        switch (key) {
        case 4:     //up
            switch (cursor_y) {
            case 10:
                cursor_y = 60;
                break;
            default:
                cursor_y -= 10;
                break;
            }
            break;
        case 1:     //down
            switch (cursor_y) {
            case 60:
                cursor_y = 10;
                break;
            default:
                cursor_y += 10;
                break;
            }
            break;
        default:
            break;
        }

        switch (cursor_y) {
        case 10:
            switch (key) {
            case 2:         //left
                switch (startcity) {
                case chicago:
                    strcpy(cityString, b[0]);
                    startcity ^= (boston | chicago);
                    break;
                case NYC:
                    strcpy(cityString, c[0]);
                    startcity ^= (chicago | NYC);
                    break;
                case stLouis:
                    strcpy(cityString, n[0]);
                    startcity ^= (NYC | stLouis);
                    break;
                case boston:
                    strcpy(cityString, s[0]);
                    startcity ^= (stLouis | boston);
                    break;
                }
                break;
            case 3:         //right
                switch (startcity) {
                case chicago:
                    strcpy(cityString, n[0]);
                    startcity ^= (NYC | chicago);
                    break;
                case NYC:
                    strcpy(cityString, s[0]);
                    startcity ^= (stLouis | NYC);
                    break;
                case stLouis:
                    strcpy(cityString, b[0]);
                    startcity ^= (boston | stLouis);
                    break;
                case boston:
                    strcpy(cityString, c[0]);
                    startcity ^= (chicago | boston);
                    break;
                }
                break;
            default:
                break;
            }
            break;
        case 20:
            switch (key) {
            case 2:     //left
                switch (i) {
                case 0:
                    i=6;
                    break;
                default:
                    i--;
                    break;
                }
                break;
            case 3:     //right
                switch (i) {
                case 6:
                    i=0;
                    break;
                default:
                    i++;
                    break;
                }
                break;
            default:
                break;
            }
            break;
        case 30:
            switch (key) {
            case 2:     //left
                switch (j) {
                case 0:
                    j=6;
                    break;
                default:
                    j--;
                    break;
                }
                break;
            case 3:     //right
                switch (j) {
                case 6:
                    j=0;
                    break;
                default:
                    j++;
                    break;
                }
                break;
            default:
                break;
            }
            break;
        case 40:
            switch (key) {
            case 2:     //left
                switch (k) {
                case 0:
                    k=6;
                    break;
                default:
                    k--;
                    break;
                }
                break;
            case 3:     //right
                switch (k) {
                case 6:
                    k=0;
                    break;
                default:
                    k++;
                    break;
                }
                break;
            default:
                break;
            }
            break;
        case 50:
            switch (key) {
            case 2:     //left
                switch (l) {
                case 0:
                    l=6;
                    break;
                default:
                    l--;
                    break;
                }
                break;
            case 3:     //right
                switch (l) {
                case 6:
                    l=0;
                    break;
                default:
                    l++;
                    break;
                }
                break;
            default:
                break;
            }
            break;
        }
    } while (kb_ScanGroup(kb_group_1) != kb_2nd);
    lom = mpp[i];
    lfm = mpp[j];
    mfm = mpp[k];
    cc = mpp[l];
}
I am going to take a break on this. I'm going to finish reading all my tutorials including C, ASM, and C++. Then I can fully understand everything I'm doing and the best way to do it.
This is the final code post for this week because school starts wednesday for me and I'm finishing the tutorials I have also.
My main screen doesn't work very well right now. I optimized it to include a sun, moon, group of stars, changing sky color. Here's the code.

Code:
/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>

/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//headers
#include "mainscreen.h"
#include "gfx/train_gfx.h"
#include "gfx/train_rail_gfx.h"

//shared libraries
#include <lib\ce\graphx.h>
#include <lib\ce\keypadc.h>

//functions
void settings();

//variables
long move;
long move1;
uint16_t skyColor;
bool dark;
int x,i;

uint8_t mainScreen() {
    extern int train_x;
    extern int train_y;
    extern long cursor_y;
    extern long cursor_x;
    extern uint8_t key;
    extern long move;
    extern long move1;
    extern uint16_t skyColor;
    extern bool dark;
mscreen:
    train_x = -156;
    train_y = 122;
    cursor_y = 160;
    cursor_x = 120;
    move = 170;
    move1 = 170;
    skyColor = 0x1E;                                //light blue
    do {
        //draw to buffer
        gfx_SetDraw(gfx_buffer);

        //make sky
        gfx_SetColor(skyColor);
        gfx_FillRectangle(0, 0, 320, 120);          //above horizon
        gfx_SetColor(gfx_black);
        gfx_Line(0, 120, 320, 120);
        dark = ifSkyisDark(skyColor);
        drawMoon_Sun(dark);
        color(move, move1);
        stars(move);
        drawStars(dark);

        //make ground
        gfx_SetColor(gfx_green);                    //medium green
        gfx_FillRectangle(0, 121, 320, 120);        //below Horizon

        //move train across screen
        gfx_Sprite(train_rail, 0, 147);
        gfx_Sprite(train_rail, 156, 147);
        gfx_Sprite(train_rail, 311, 147);
        gfx_TransparentSprite(train, train_x, train_y);
        train_x += 5;
        if (train_x >= 320) {                       //resets train
            train_x = -155;
        }

        //main menu
        gfx_PrintStringXY("New Game", (160-(gfx_GetStringWidth("New Game")/2)), 160);
        gfx_PrintStringXY("Load Game", (160-(gfx_GetStringWidth("Load Game")/2)), 170);
        gfx_PrintStringXY("Settings", (160-(gfx_GetStringWidth("Settings")/2)), 180);
        gfx_PrintStringXY("Quit", (160-(gfx_GetStringWidth("Quit")/2)), 190);
        gfx_PrintStringXY(">", cursor_x, cursor_y);

        //choose menu item
        key = os_GetCSC();
        switch (key) {

        case 4: //up

            switch (cursor_y) {

            case 160: //New Game going to  Quit
                cursor_y = 190;
                cursor_x = 135;
                break;
            case 170: //Load Game to New Game
                cursor_y = 160;
                cursor_x = 120;
                break;
            case 180: //Settings to Load Game
                cursor_y = 170;
                cursor_x = 115;
                break;
            case 190: //Quit to Settings
                cursor_y = 180;
                cursor_x = 120;
                break;
            default:
                break;
            }
            gfx_SwapDraw();
            break;

        case 1: //down

            switch (cursor_y) {

            case 160: //New Game to Load Game
                cursor_y = 170;
                cursor_x = 115;
                break;
            case 170: //Load Game to Settings
                cursor_y = 180;
                cursor_x = 120;
                break;
            case 180: //Settings to Quit
                cursor_y = 190;
                cursor_x = 135;
                break;
            case 190: //Quit to New Game
                cursor_y = 160;
                cursor_x = 120;
                break;
            default:
                break;
            }
            gfx_SwapDraw();
            break;

        default:
            gfx_SwapDraw();
            break;
        }
    } while (kb_ScanGroup(kb_group_1) != kb_2nd);
    if (cursor_y == 180) {
        while (kb_AnyKey()) {}
        settings();
        while (kb_AnyKey()) {}
        goto mscreen;
    }
    return cursor_y;
}

void color(long sunHeight, long moonHeight) {
    extern uint16_t skyColor;
    if (sunHeight != 0) {
        switch (sunHeight) {
        case -75:
            skyColor = 0x14;
            break;
        case -100:
            skyColor = 0x1C;
            break;
        case -125:
            skyColor = 0x3C;
            break;
        case -150:
            skyColor = 0x34;
            break;
        case -200:
            skyColor = 0x32;
            break;
        case -220:
            skyColor = 0x1A;
            break;
        case -250:
            skyColor = 0x10;
            break;
        case -275:
            skyColor = 0x08;
            break;
        case -300:
            skyColor = 0x28;
            break;
        case -350:
            skyColor = gfx_black;
            break;
        }
    }
    if (moonHeight != 0) {
        switch (moonHeight) {
        case -75:
            skyColor = 0x28;
            break;
        case -100:
            skyColor = 0x08;
            break;
        case -125:
            skyColor = 0x10;
            break;
        case -150:
            skyColor = 0x1A;
            break;
        case -200:
            skyColor = 0x32;
            break;
        case -220:
            skyColor = 0x34;
            break;
        case -250:
            skyColor = 0x3C;
            break;
        case -275:
            skyColor = 0x1C;
            break;
        case -300:
            skyColor = 0x14;
            break;
        case -350:
            skyColor = 0x1E;
            break;
        }
    }
    return skyColor;
}

bool ifSkyisDark(uint16_t skyColor) {
    switch (skyColor) {
    case 0x1A:
        return true;
    case 0x10:
        return true;
    case 0x08:
        return true;
    case 0x28:
        return true;
    case gfx_black:
        return true;
    default:
        return false;
    }
}

void stars(long sunHeight) {
    extern uint16_t star_array[40][2];
    extern int x;
    if ((sunHeight >= 100) && (sunHeight <=138)) {
    star_array[x][0] = rand()%320 +1;
    star_array[x][1] = rand()%240 +1;
    x++;
    srand(rtc_Time());
    } else {
        x = 0;
    }
}

/*long drawSun(long moonHeight) {
    extern int train_x;
    if (moonHeight == 170) {
        gfx_SetColor(gfx_yellow);
        gfx_FillCircle(160,move,50);
        //moves sun for every time train_x is divisible by 5
        if (train_x%5 == 0) {
            move -= 1;
        }
    }
    if (move == 400) {
        move = 170;
    }
}

long drawMoon(long sunHeight) {
    extern int train_x;
    if (sunHeight == 170) {
        gfx_SetColor(0x15);
        gfx_FillCircle(160,move1,20);
        //moves sun for every time train_x is divisible by 5
        if (train_x%5 == 0) {
            move1 -= 1;
        }
    }
    if (move1 == 400) {
        move1 = 170;
    }
}*/

void drawMoon_Sun(bool dark) {
    extern long move;
    extern long move1;
    extern int train_x;
    if ((!dark) && (move1 == 170)) {
        gfx_SetColor(gfx_yellow);
        gfx_FillCircle(160,move,50);
        //moves sun for every time train_x is divisible by 5
        if (train_x%5 == 0) {
            move -= 1;
        }
        if (move == 400) {
            move = 170;
        }
    }
    if ((dark) && (move == 170)) {
        gfx_SetColor(0x15);
        gfx_FillCircle(160,move1,20);
        //moves sun for every time train_x is divisible by 5
        if (train_x%5 == 0) {
            move1 -= 1;
        }
        if (move1 == 400) {
            move1 = 170;
        }
    }
}

void drawStars(bool dark) {
    extern int train_x;
    extern uint16_t star_array[40][2];
    extern int i;
    if (dark) {
        gfx_SetColor(gfx_white);
        if ((train_x >= 0) && (train_x <=38)) {
            gfx_SetPixel(star_array[i][0], star_array[i][1]);
            i++;
        }
        if (i > 38) {
            i = 0;
        }
    }
}

I know Rico has helped me out with my graphics menu's problems, so thanks to him, my settings works. I tried to figure out what to do with this in the sense of adding an if (key) {} to Swap Draw, but since my train and the sun moon and stars all move, I don't know how to do it. Help. Smile
After reading some of a C tutorial, I came to realize that some of my code is redundant. I will clean it up next time I get to it. Once I finish that, and debug the main screen, I will post my progress.
What is the calculator equivalent to scanf()?
Does the write mode for ti-Open() overwrite the AppVar automatically, or does it only do so for the variables written to using ti-Write()?
Progress Update:
I am reorganizing the entire structure to be more efficient. Something is wrong with my settings, because the strings won't switch when I click the left or right button, on the bottom 3 settings. I think I'll figure this out. Does opening an appvar have any effect on code? When should you close an appvar(as in use ti-CloseAll())?
I'm holding off on the sky changing colors for a version update in the future. Once I get the appvar and settings configured, I am definitely moving on to the main game. Seems a bit late but, I'm confident.
Can anyone explain to me how to use, and what is the VRAM in the C Libraries? I'm trying to create a popup box on the screen but I don't want the screen to completely reset, just the are the popup box is in, and then set it back to what it was before. I don't know if you can do that with buffers, or VRAM or whatever, so please explain the VRAM, and any tips on how to do this. Thanks Smile
Also, I can't figure out the problem in my settings. I printed my cursor position, key, and the settings values to the screen to see what the problem was. The problem was, the integers won't increment or decrement. They just stay the same.

Code:
int settings() {
    uint8_t key;
    long cursor_y;
    int startcity,trainsVar,highscore=0;
    int i=1,j=2,k=3,l=6;//each int is for the same array, but for different aspects

    ti_CloseAll();
    trainsVar = ti_Open("Trains", "r");
    if (trainsVar) {
        ti_Read(&highscore, sizeof(int), 1, trainsVar);
    }

    startcity = chicago;
    strcpy(cityString, c);
    cursor_y = 10;
    key = 5;
    gfx_SetDraw(gfx_buffer);
    do {
        if(key) {
            while (kb_AnyKey());
            switch (key) {
            case 4:     //up
                switch (cursor_y) {
                case 10:
                    cursor_y = 50;
                    break;
                default:
                    cursor_y -= 10;
                    break;
                }
                break;
            case 1:     //down
                switch (cursor_y) {
                case 50:
                    cursor_y = 10;
                    break;
                default:
                    cursor_y += 10;
                    break;
                }
                break;
            }
            gfx_FillScreen(0x80);
            gfx_PrintStringXY(">", 10, cursor_y);
            gfx_PrintStringXY("Start City:", 20, 10);
            gfx_PrintStringXY(cityString, 100, 10);
            gfx_PrintStringXY(lomc, 20, 20);                //less than 100 miles(161 kilometer)
            gfx_PrintStringXY(mppc[i], 100, 20);            //amount
            gfx_PrintStringXY(lfmc, 20, 30);                //less than 500 miles(161 kilometer)
            gfx_PrintStringXY(mppc[j], 100, 30);            //amount
            gfx_PrintStringXY(mfmc, 20, 40);                //more than 500 miles(161 kilometer)
            gfx_PrintStringXY(mppc[k], 100, 40);            //amount
            gfx_PrintStringXY(ccc, 20, 50);                 //cargo charge per 1000 lbs(453 kilogram)
            gfx_PrintStringXY(mppc[l], 150, 50);            //amount
            gfx_PrintStringXY("Press 2nd when done", 20, 60);
            gfx_SetTextXY(10,150);
            gfx_PrintInt(i,1);
            gfx_SetTextXY(10,160);
            gfx_PrintInt(j,1);
            gfx_SetTextXY(10,170);
            gfx_PrintInt(k,1);
            gfx_SetTextXY(10,180);
            gfx_PrintInt(l,1);
            gfx_SetTextXY(10,190);
            gfx_PrintInt(cursor_y,3);
            gfx_SetTextXY(10,200);
            gfx_PrintInt(key,3);
            gfx_SwapDraw();
        }


        key = os_GetCSC();

        switch (cursor_y) {
        case 10:
            switch (key) {
            case 2:         //left
                switch (startcity) {
                case chicago:
                    strcpy(cityString, b);
                    startcity ^= (boston | chicago);
                    break;
                case NYC:
                    strcpy(cityString, c);
                    startcity ^= (chicago | NYC);
                    break;
                case stLouis:
                    strcpy(cityString, n);
                    startcity ^= (NYC | stLouis);
                    break;
                case boston:
                    strcpy(cityString, s);
                    startcity ^= (stLouis | boston);
                    break;
                }
                break;
            case 3:         //right
                switch (startcity) {
                case chicago:
                    strcpy(cityString, n);
                    startcity ^= (NYC | chicago);
                    break;
                case NYC:
                    strcpy(cityString, s);
                    startcity ^= (stLouis | NYC);
                    break;
                case stLouis:
                    strcpy(cityString, b);
                    startcity ^= (boston | stLouis);
                    break;
                case boston:
                    strcpy(cityString, c);
                    startcity ^= (chicago | boston);
                    break;
                }
                break;
            }
            break;
        case 20:
            switch (key) {
            case 2:     //left
                switch (i) {
                case 0:
                    i=6;
                    break;
                default:
                    i--;
                    break;
                }
                break;
            case 3:     //right
                switch (i) {
                case 6:
                    i=0;
                    break;
                default:
                    i++;
                    break;
                }
                break;
            }
            break;
        case 30:
            switch (key) {
            case 2:     //left
                switch (j) {
                case 0:
                    j=6;
                    break;
                default:
                    j--;
                    break;
                }
                break;
            case 3:     //right
                switch (j) {
                case 6:
                    j=0;
                    break;
                default:
                    j++;
                    break;
                }
                break;
            }
            break;
        case 40:
            switch (key) {
            case 2:     //left
                switch (k) {
                case 0:
                    k=6;
                    break;
                default:
                    k--;
                    break;
                }
                break;
            case 3:     //right
                switch (k) {
                case 6:
                    k=0;
                    break;
                default:
                    k++;
                    break;
                }
                break;
            }
            break;
        case 50:
            switch (key) {
            case 2:     //left
                switch (l) {
                case 0:
                    l=7;
                    break;
                default:
                    l--;
                    break;
                }
                break;
            case 3:     //right
                switch (l) {
                case 7:
                    l=0;
                    break;
                default:
                    l++;
                    break;
                }
                break;
            }
            break;
        }
    } while (kb_ScanGroup(kb_group_1) != kb_2nd);
    lom = mpp[i];
    lfm = mpp[j];
    mfm = mpp[k];
    cc = mpp[l];
    ti_CloseAll();
    trainsVar = ti_Open("Trains", "w");
    if (trainsVar) {
        ti_Write(&highscore, sizeof(int), 1, trainsVar);
        ti_Write(&startcity, sizeof(int), 1, trainsVar);
        ti_Write(&lom, sizeof(float), 1, trainsVar);
        ti_Write(&lfm, sizeof(float), 1, trainsVar);
        ti_Write(&mfm, sizeof(float), 1, trainsVar);
        ti_Write(&cc, sizeof(float), 1, trainsVar);
    }
    ti_CloseAll();
    return 1;
}


The numbers that change and do not change are in order from top to bottom as:
int i
int j
int k
int l
long cursor_y
int key
Does anyone have their own way to do settings in a game? I think my code is flawed so I want to completely redo it. Any ideas?
I decided to drop the settings for now. I'm taking it out completely. I'm going to finish the main game. Which hopefully does not take long, and then see if I can implement the settings again. Ideas for the settings are always welcome.
Great time for ideas to pop into your head, 1.5 weeks before the due date. I'm going to have updates hopefully by Wednesday so stay tuned.

What I'm adding:
3 possible saved games
InGame Settings
Finishing the actual Game

Thankfully I should be able to finish this by next week, as school allows. Hope I finish.
And this is my problem with the compressed sprite.

Here's the code where I decompress the sprites:

Code:
#include <stdlib.h>
#include <string.h>
#include <errno.h>

//shared libraries
#include <lib\ce\graphx.h>

//sprites
#include "gfx\train_gfx.h"

//functions
int mainScreen();
int closeVar();

int main() {

    //setup
    malloc(0);
    train = gfx_AllocSprite(139,25, malloc);
    train_rail = gfx_AllocSprite(156,3,malloc);
    map = gfx_AllocSprite(198,122,malloc);
    gfx_Begin(gfx_8bpp);
    gfx_SetPalette(train_gfx_pal, sizeof(train_gfx_pal), 0);

    gfx_LZDecompressSprite(train_data_compressed, train);
    gfx_LZDecompressSprite(train_rail_data_compressed, train_rail);
    gfx_LZDecompressSprite(map_data_compressed, map);

    //main screen
    errno = mainScreen();
    closeVar();

    //end and Cleanup
    while( !os_GetCSC() );
    free(train);
    free(train_rail);
    free(map);
    gfx_End();
    prgm_CleanUp();
    return 0;
}

Here's the code where I use the sprites:

Code:
int mainScreen() {
    int move;
    int quit=0;
    signed int train_x;
    int train_y;
    long cursor_x;
    int errno=0;
    int trainsVar;
    bool gaccess=0;

    do {
        train_x = -160;
        train_y = 122;
        cursor_y = 160;
        cursor_x = 120;
        move = 170;
        do {
            //draw to buffer
            gfx_SetDraw(gfx_buffer);

            //make sky
            gfx_SetColor(0x1E);
            gfx_FillRectangle(0, 0, 320, 120);          //above horizon
            gfx_SetColor(gfx_white);
            gfx_Line(0, 120, 320, 120);

            //make sun
            gfx_SetColor(gfx_yellow);
            gfx_FillCircle(160, move, 50);
            if (train_x%5 == 0)
                move--;
            if (move == -250)
                move = 170;

            //make ground
            gfx_SetColor(gfx_green);                    //medium green
            gfx_FillRectangle(0, 121, 320, 120);        //below Horizon

            //move train across screen
            gfx_Sprite(train_rail, 0, 147);
            gfx_Sprite(train_rail, 156, 147);
            gfx_Sprite(train_rail, 311, 147);
            gfx_TransparentSprite(train, train_x, train_y);
            train_x += 5;
            if (train_x >= 320) {                       //resets train
                train_x = -160;
            }

            gfx_PrintStringXY("BY: SEANLEGO23", 0, 230);
            gfx_PrintStringXY("v1.0", 320-gfx_GetStringWidth("v1.0"), 230);
            dispHS();
            chooseMode();
            gfx_SwapDraw();
        } while (key != 255);
I officially resign from this contest. Reasons being are as follows(in order of importance):
1. I am completely busy the next two nights.
2. I spent way too long trying to fix my settings
3. The game is too big to finish that quickly with my not so great C skills.
I will continue this game. Hopefully I'll submit it to the archives by the end of this year, but I do not know. I wish the rest of you luck. One question: Should I continue to use this topic for my updates or should I create a new one?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 3 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement