Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2014-08-14 19:54:45

a cat
Member
Registered: 2014-07-27
Posts: 98

variable behaving weirdly gbdk

hi i am working on a programming language that will run on the gameboy
but when trying to increment a certain variable variable it turns into -17919
also when i increment it in main it works fine

this is the array were the variabe is located:
unsigned char cnt[5] = {1,2,3,4,5}; //declaired in int main()

and here is the header file that contains the function that
tries to increment it and weird things happen:

unsigned char interpret(unsigned char c);//under construction

extern unsigned char cnt[5];//array located in main

/*
return codes
1 = error: attempt to go before line 1
2 = error: attempt to go past line 124
*/
unsigned char interpret(unsigned char c){
    switch(c){
        case '^':
            if(cnt[0] <= 1){return 1;}
            cnt[0]++;cnt[1]++;
            cnt[2]++;cnt[3]++;
            cnt[4]++;
        case 'v':
            if(cnt[0] >= 124){return 2;}
            cnt[0]--;cnt[1]--;
            cnt[2]--;cnt[3]--;
            cnt[4]--;
        default:
            break;
    }
}
also if it helps heres main():
int main(){
Clear_mem();
Clear_code();
    while(running == 1){
    display(cnt[0],cnt[1],cnt[2],cnt[3],cnt[4]);
    printf("cnt[0] = %d\n", cnt[0]);
    printf("Press Start To Enter   Next Character\n");
    waitpad(J_START);
    code[k] = input();
    interpret(code[k]);
    k++;
    }
return 0;
}


a cat in need of knowledge!!

Offline

 

#2 2014-08-25 14:52:27

a cat
Member
Registered: 2014-07-27
Posts: 98

Re: variable behaving weirdly gbdk

PROBLEM SOLVED


a cat in need of knowledge!!

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson