help with struct problem

Started by
5 comments, last by kingpinzs 19 years, 4 months ago
why does this strcut come up with syntax error

struct Tile
{
int Tile_size;
int world_sizex;
int world_sizey;
int Screen_sizex;
int Screen_sizey;
int world_camerax;
int world_cameray;
int scroll_x;
int scroll_y;
int offset_x;
int offset_y;
int tiles;
int x;
int y;
bool wakable;
}; 
    
Tile Tileset;
 
 Tileset.Tile_size = 32;
 Tileset.world_sizex = 25;
 Tileset.world_sizey = 48;
 Tileset.Screen_sizex = 25;
 Tileset.Screen_sizey = 24;


Tileset.world_camerax = 0;
Tileset.world_cameray = 0;
Tileset.wakable = true;

char map[Tileset.world_sizey][Tileset.world_sizex] = {//lost of number here

Tileset.Tile_size = 32; syntax error before `.' token it says that for all of them. it is declared in that oerder in my tile.h file How do I fix this?
Advertisement
"Tileset.Tile_size = 32;" is a statement, not a declaration. As such, it can't go in global context. It has to be inside a function.
You can fix it by removing all the Tileset.blah = statements and initializing the struct as follows:

Tile Tileset = { 32, 25, 48, 25, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, true };

OR

Tile Tileset = { .Tile_size = 32, .world_sizex = 25, .world_sizey = 48, .Screen_sizex = 25, .Screen_sizey = 24, .world_camerax = 0, .world_cameray = 0, .wakable = true };

Note: The second method may not work on all compilers (MSVC), but it is standard.
Ra
well this "Tile Tileset = { 32, 25, 48, 25, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, true };" worked for me

but now how do I make some of the tiles unwakeable?

I think it some thing like this

if Tileset.wakable = false then
something witch I am not sure what to do here.
The only time you'd want to know if a tile is walkable is when something tries to move onto it.

So, you'd have something like this:

// pseudo-codeclass::TryingToMove(){  if(NodeImTryingToMoveTo.walkable == true)    moveToNode();  else    doNothing();};


Hope that's clear.
Jim.
Quote:Original post by Ra
Note: The second method may not work on all compilers (MSVC), but it is standard.
Uh, which standard are you referring to? I've never seen that construction in C++.
this is what I have so far

if (Tileset.tiles <= 1 && Tileset.tiles >= 3){ Tileset.wakable = true;} else if (Tileset.tiles == 2){ Tileset.wakable = false;} if (Tileset.tiles == true)                {                Tileset.world_cameray +=8;                              if(Players.y != 1200)              {                 Players.y +=4;                   if (Players.cr != 192 )                  {                  Players.cl += 64;                  Players.cr += 64;                  Players.ct = 64;                  Players.cb = 128;               }                    else if ( Players.cr == 192)                  {                      Players.cl = 0;                      Players.cr = 64;                  }                   }                            }        

and it does not work. I guess that tiles never = 2 when it is spose to

What is the theory behind making tiles unwalkable?






This topic is closed to new replies.

Advertisement