I am programming a game, and there is a syntax error, but I know for a fact that the syntax is correct.

These are the errors:
ERROR (100) Syntax error
WARNING (222) Statement has no effect
ERROR (128) Identifier "gmode" not defined within current scope

I will put in comments, in the code, on the line it says syntax error for.

Thanks if you know what is going on.

Here is the code:


Code:

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <keypadc.h>
#include <graphx.h>
#include "gfx/logo_gfx.h"

void play();
void gameMode();

void main(void) {

    uint8_t leave = 0;
    uint8_t pick = 0;

    gfx_Begin();
    gfx_SetPalette(logo_gfx_pal, sizeof_logo_gfx_pal, 0);
    gfx_FillScreen(7);
    gfx_PrintStringXY("PONG",135,100);
    gfx_PrintStringXY("--------------",100,110);
    gfx_PrintStringXY("Press [CLEAR] to Exit",80,130);
    gfx_PrintStringXY("Press [ENTER] to Play",80,120);
    gfx_PrintStringXY("Press [MODE] to Change Game Mode",45,140);

    while(leave==0){
        kb_Scan();
        if (kb_Data[6] == kb_Clear)
            leave=1;
        if (kb_Data[6] == kb_Enter){
            gfx_FillScreen(7);
            play();
        }
        if (kb_Data[6] == kb_Mode)
            gameMode();
    }
    gfx_End();
    os_ClrHome();
}

void gameMode(){
    gfx_FillScreen(7);
    gfx_PrintStringXY("Choose Game Mode:",50,50);
    gfx_PrintStringXY("1: Normal",50,60);
    gfx_PrintStringXY("2: Acceleration",50,70);

    int8_t gmode = 0; //line with syntax error

    while (gmode == 0){
        kb_Scan();
        if (kb_Data[3] == kb_1)
            gmode = 1;
        if (kb_Data[4] == kb_2)
            gmode = 2;
    }
}
Make a single topic for all your programming questions. The issue is the variable isn't declared at the top of the scope, hence the syntax error.
Move the declaration of the variable "gmode" to the beginning of the scope (in that case, right before "gfx_FillScreen(7)").

Also, separate declaring the variable, and assigning the variable into two separate lines.

Code:

int8_t gmode;
gmode = 0;
k. this topic will be it. I will edit the title now. sry. I am new with this forum stuff.
Quote:
Move the declaration of the variable "gmode" to the beginning of the scope (in that case, right before "gfx_FillScreen(7)").

Also, separate declaring the variable, and assigning the variable into two separate lines.


Still says syntax error.
KryptonicDragon wrote:
Move the declaration of the variable "gmode" to the beginning of the scope (in that case, right before "gfx_FillScreen(7)").

Also, separate declaring the variable, and assigning the variable into two separate lines.

Code:

int8_t gmode;
gmode = 0;
I just woke up...restarted my computer, and the syntax error went away for no reason. Weird.
  
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 1 of 1
» 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