Sign in to follow this  

help with struct problem

This topic is 4763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
"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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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-code
class::TryingToMove()
{
if(NodeImTryingToMoveTo.walkable == true)
moveToNode();
else
doNothing();
};



Hope that's clear.
Jim.

Share this post


Link to post
Share on other sites
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++.

Share this post


Link to post
Share on other sites
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[P].y != 1200)
{
Players[P].y +=4;
if (Players[P].cr != 192 )
{
Players[P].cl += 64;
Players[P].cr += 64;
Players[P].ct = 64;
Players[P].cb = 128;
}
else if ( Players[P].cr == 192)
{
Players[P].cl = 0;
Players[P].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?






Share this post


Link to post
Share on other sites

This topic is 4763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this