0

Hello so i am working on a simple falling sand game and i am getting the constant expression expected error im compiling with tcc using tcc -o fallingsand.exe fallingsand.c world.c C:\raylib\raylib\src\raylib.rc.data -Os -std=c99 -Wall -Iextenal -DPLATFORM_DESKTOP -msvcrt -lraylib -lopengl32 -lwinmm -lkernel32 -lshell32 -luser32 -Wl
I cant tell what is not constant and not defined in my code. Thank you.

fallingsand.c(main file)

#include "world.h"
int main(int argc, char** argv){
    const int WIDTH = 800;
    const int HEIGHT = 600;
    InitWindow(WIDTH, HEIGHT, "Falling Sand");
    SetTargetFPS(144);
    init();
    Vector2 mousePos = {1.0f, 1.0f};
    while(!WindowShouldClose()){
        mousePos = GetMousePosition();
        if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) place(
        mousePos.x, mousePos.y, SAND);
        draw();
    }
}

world.h

#include "raylib.h"
#include <stdlib.h>
#ifndef WORLD_H
#define WORLD_H
const int AIR = 0;
const int SAND = 1;
const int WATER = 2;
int world[800][600];
int worldF[800][600];
void init();
void place(int x, int y, int type);
void draw();
void drop();
#endif

world.c

#include "world.h"
void init(){
    for(int y = 0; y < 600; y++){
        for(int x = 0; x < 800; x++){
            world[x][y] = AIR;
            worldF[x][y] = 0;
        }
    }
}
void place(int x, int y, int type){
    if(worldF[x][y] == 0) {
        world[x][y] = type;
        worldF[x][y] = 1;
    }
    else {}
}
void draw(){
    for(int y = 0; y < 600; y += 5){
        for(int x = 0; x < 800; x += 5){
            switch(world[x][y]){
                Vector2 pos = {x, y};
                case AIR: DrawRectangleV(pos, 5, 5, BLACK); break;
                case SAND: DrawRectangleV(pos, 5, 5, YELLOW); break;
                case WATER: DrawRectangleV(pos, 5, 5, BLUE); break;
                default: DrawRectangleV(pos, 5, 5, RED); break;
            }
        }
    }
}

error this is the edit

world.c:22: error: constant expression expected
world.c: error: 'AIR' defined twice
world.c: error: 'SAND' defined twice
world.c: error: 'WATER' defined twice
koukah
  • 69
  • 1
  • 6
  • Doesn't your compiler tell you `file_name:line_number;column_number: The error is on this line: `? Please post the full error message verbatim from your compiler. `int world[800][600];` You should not put global variable definitions in a header file - you will get multiple definitions error as each `.c` file will have it's own _copy_ of the variables.. Maybe could you re-read an introduction to header files in C? – KamilCuk Mar 28 '21 at 22:43
  • I know about them but normally when you get one error its like a domino so i thought the error i specified was the one leading to the rest, i updated it btw – koukah Mar 28 '21 at 22:46

0 Answers0