Thread: Struct Problem

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    48

    Struct Problem

    So I was watching a tutorial where a guy did this but on iOS. I tried the same here on Windows and there are some errors. Any sugestion to fix this ?

    structs:
    Code:
    ///////////////////////////////////////////////////////
    //STRUCT FOR PLAYER DATAS
    ///////////////////////////////////////////////////////
    
    typedef struct
    {
      float x, y;
      float dx, dy;
      short life;
      char *name;
      int onLedge;
    
      int animFrame, facingLeft, slowingDown;
    } Player;
    
    ///////////////////////////////////////////////////////
    //STRUCT FOR LEDGE
    ///////////////////////////////////////////////////////
    
    
    typedef struct
    {
      int x, y, w, h;
    } Ledge;
    
    ///////////////////////////////////////////////////////
    //STRUCT GAMESTATE
    ///////////////////////////////////////////////////////
    
    
    typedef struct
    {
      //Players
      Player PL[2];
    
      //Ledges
      Ledge ledges[100];
    
      //Images
      SDL_Texture *manFrames[2];
      SDL_Texture *brick;
    
      int time;
    
      //Renderer
      SDL_Renderer *renderer;
    } GameState;
    Function of the problem:
    Code:
    void process(GameState *game)
    {
      //add time
      game->time++;
    
      //man movement
      Player *PL[0] = &game->PL[0]; //Invalid initializer
      game.PL[0].x += game.PL[0].dx;  //Error: Request for member 'PL' in something not a structure or union
      game.PL[0].y += game.PL[0].dy;
    
      if(PL[0]->dx != 0 && PL[0]->onLedge && !PL[0]->slowingDown)
      //////////////////////////////////////////
    Last edited by MrPecanha; 06-24-2016 at 04:30 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Player *PL[0] = &game->PL[0]; //Invalid initializer
    How are you supposed to have an array with zero elements?

    Also, you need braces around your array initialiser.

    Perhaps you meant things like
    Player *PL = &game->PL[0]; //Invalid initializer
    game->PL[0].x += game->PL[0].dx; //Error: Request for member 'PL' in something not a structure or union
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Struct problem?
    By Shackdaddy836 in forum C Programming
    Replies: 6
    Last Post: 09-10-2011, 07:57 PM
  2. struct struct struct problem....please....help!!!
    By nullifyed in forum C Programming
    Replies: 5
    Last Post: 06-19-2010, 08:19 AM
  3. Help with a Struct problem
    By Brownie in forum C++ Programming
    Replies: 3
    Last Post: 10-01-2008, 11:58 AM
  4. Struct problem
    By totalfreeloader in forum C++ Programming
    Replies: 5
    Last Post: 01-07-2003, 09:27 AM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM

Tags for this Thread