Archived

This topic is now archived and is closed to further replies.

for (index=0; index<MAX_ROCKS; index++)

This topic is 5272 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

I''m having a problem with for (index=0; index
void Move_Rocks(void)
{
// this function moves all the rocks pulses and checks for

// collision with the rocks


for (int index=0; index<MAX_ROCKS; index++)
    {
    // test if rocks pulse is in flight

    if (rocks[index].state == ROCK_STATE_ON)
        {
        // move the rock

        Move_BOB(&rocks[index]);

        // add player motion in

        if (moving_up)
            rocks[index].y+=(rocks[index].yv>>1);

        // test if rock is off screen

        if (rocks[index].y > SCREEN_HEIGHT)
           {
           // kill rock and put back on available list

           rocks[index].state = ROCK_STATE_OFF;
           } // end if

        
        } // end if


    } // end for index


// now test if it''s time to add a new rock to the list

if ((rand()%6)==3)
   {
   // scan for a rock to initialize

   for (index=0; index<MAX_ROCKS; index++)
       {
       // is this rock available?

       if (rocks[index].state == ROCK_STATE_OFF)
          {
          // set animation rate

          Set_Anim_Speed_BOB(&rocks[index],1+rand()%5);
    
          // set velocity

          Set_Vel_BOB(&rocks[index], -4+rand()%8, 4+rand()%12);
    
          // set position

          Set_Pos_BOB(&rocks[index], rand()%SCREEN_WIDTH, -128);
    
          // set size of rock

          rocks[index].varsI[0] = rand()%3;
          rocks[index].varsI[1] = rock_sizes[rocks[index].varsI[0]];
          
          // set strength of rock

          switch(rocks[index].varsI[0])
                {
                case ROCK_LARGE:
                     {
                     // set hardness of rock

                     rocks[index].varsI[2] = 100+rand()%100;
                     } break;
 
                case ROCK_MEDIUM:
                     {
                     // set hardness of rock

                     rocks[index].varsI[2] = 40 + rand()%30;
                     } break;     

                case ROCK_SMALL:
                     {
                     // set hardness of rock

                     rocks[index].varsI[2] = 10;
                     } break;

                default:break;

                } // end switch


          // turn rock on

          rocks[index].state = ROCK_STATE_ON;
          
          // later

          return;

          } // end if


       } // end for index


   } // end if


} // end Move_Rocks

Share this post


Link to post
Share on other sites
The symbol 'index' is undefined in the second loop, according to the C++ standard scoping rules.

Change this

// now test if it's time to add a new rock to the list
if ((rand()%6)==3)
{
// scan for a rock to initialize
for (index=0; index<MAX_ROCKS; index++)


to this

// now test if it's time to add a new rock to the list
if ((rand()%6)==3)
{
// scan for a rock to initialize
for (int index=0; index<MAX_ROCKS; index++)


Edit: beaten to it


[edited by - Yann L on July 7, 2003 2:59:42 PM]

Share this post


Link to post
Share on other sites
sounds like dev-c++ to me =)

what''s wrong with declaring it local to that function?

eg..

void Move_Rocks(void)
{
int index;
...


I fseek, therefore I fam.

Share this post


Link to post
Share on other sites
it helped solve the problem. But it brought up about 100 more...

C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x6b3):starfe~1.cpp: undefined reference to `DD_Lock_Back_Surface(void)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x6cc):starfe~1.cpp: undefined reference to `back_lpitch'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x6d2):starfe~1.cpp: undefined reference to `back_buffer'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x712):starfe~1.cpp: undefined reference to `Draw_Pixel(int, int, int, unsigned char *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x721):starfe~1.cpp: undefined reference to `DD_Unlock_Back_Surface(void)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x74f):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x754):starfe~1.cpp: undefined reference to `Load_Bitmap_File(BITMAP_FILE_TAG *, char *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x79a):starfe~1.cpp: undefined reference to `Create_BOB(BOB_TYP *, int, int, int, int, int, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x7c0):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x7dd):starfe~1.cpp: undefined reference to `Load_Frame_BOB(BOB_TYP *, BITMAP_FILE_TAG *, int, int, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x80e):starfe~1.cpp: undefined reference to `Set_Anim_Speed_BOB(BOB_TYP *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x844):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x849):starfe~1.cpp: undefined reference to `Unload_Bitmap_File(BITMAP_FILE_TAG *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x88c):starfe~1.cpp: undefined reference to `Destroy_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x9dc):starfe~1.cpp: undefined reference to `Move_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x11e8):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1206):starfe~1.cpp: undefined reference to `Draw_BOB(BOB_TYP *, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1229):starfe~1.cpp: undefined reference to `Animate_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1346):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x134b):starfe~1.cpp: undefined reference to `Load_Bitmap_File(BITMAP_FILE_TAG *, char *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1369):starfe~1.cpp: undefined reference to `Create_BOB(BOB_TYP *, int, int, int, int, int, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x13ce):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x13d8):starfe~1.cpp: undefined reference to `Load_Frame_BOB(BOB_TYP *, BITMAP_FILE_TAG *, int, int, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x141c):starfe~1.cpp: undefined reference to `Set_Anim_Speed_BOB(BOB_TYP *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x146c):starfe~1.cpp: undefined reference to `Set_Vel_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x14bd):starfe~1.cpp: undefined reference to `Set_Pos_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x15aa):starfe~1.cpp: undefined reference to `Set_Anim_Speed_BOB(BOB_TYP *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x160d):starfe~1.cpp: undefined reference to `Set_Vel_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1671):starfe~1.cpp: undefined reference to `Set_Pos_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x171b):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1720):starfe~1.cpp: undefined reference to `Unload_Bitmap_File(BITMAP_FILE_TAG *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x176c):starfe~1.cpp: undefined reference to `Destroy_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x17dc):starfe~1.cpp: undefined reference to `Move_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x193b):starfe~1.cpp: undefined reference to `Set_Anim_Speed_BOB(BOB_TYP *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x19b3):starfe~1.cpp: undefined reference to `Set_Vel_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1a09):starfe~1.cpp: undefined reference to `Set_Pos_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1c5b):starfe~1.cpp: undefined reference to `Set_Anim_Speed_BOB(BOB_TYP *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1c86):starfe~1.cpp: undefined reference to `Set_Vel_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1cb1):starfe~1.cpp: undefined reference to `Set_Pos_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1e9d):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1eef):starfe~1.cpp: undefined reference to `Draw_Scaled_BOB(BOB_TYP *, int, int, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1efc):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1f1a):starfe~1.cpp: undefined reference to `Draw_BOB(BOB_TYP *, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1f3d):starfe~1.cpp: undefined reference to `Animate_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1f70):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1f75):starfe~1.cpp: undefined reference to `Load_Bitmap_File(BITMAP_FILE_TAG *, char *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1f93):starfe~1.cpp: undefined reference to `Create_BOB(BOB_TYP *, int, int, int, int, int, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x1ffe):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2008):starfe~1.cpp: undefined reference to `Load_Frame_BOB(BOB_TYP *, BITMAP_FILE_TAG *, int, int, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x201f):starfe~1.cpp: undefined reference to `Set_Anim_Speed_BOB(BOB_TYP *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2094):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2099):starfe~1.cpp: undefined reference to `Unload_Bitmap_File(BITMAP_FILE_TAG *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x20e4):starfe~1.cpp: undefined reference to `Destroy_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x214f):starfe~1.cpp: undefined reference to `Move_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x22f1):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2343):starfe~1.cpp: undefined reference to `Draw_Scaled_BOB(BOB_TYP *, int, int, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2354):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2372):starfe~1.cpp: undefined reference to `Draw_BOB(BOB_TYP *, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2395):starfe~1.cpp: undefined reference to `Animate_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x240e):starfe~1.cpp: undefined reference to `Set_Anim_Speed_BOB(BOB_TYP *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2456):starfe~1.cpp: undefined reference to `Set_Vel_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2481):starfe~1.cpp: undefined reference to `Set_Pos_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2571):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2585):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x25ab):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x25e0):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2606):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x261d):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2684):starfe~1.cpp: undefined reference to `lpddsprimary'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x26d2):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2736):starfe~1.cpp: undefined reference to `lpddsprimary'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2773):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x27d9):starfe~1.cpp: undefined reference to `lpddsprimary'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2827):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2894):starfe~1.cpp: undefined reference to `lpddsprimary'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x28d1):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2939):starfe~1.cpp: undefined reference to `lpddsprimary'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2987):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x29f4):starfe~1.cpp: undefined reference to `lpddsprimary'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2a31):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2a99):starfe~1.cpp: undefined reference to `DD_Init(int, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2aa9):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2aae):starfe~1.cpp: undefined reference to `Load_Bitmap_File(BITMAP_FILE_TAG *, char *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2ab9):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2abe):starfe~1.cpp: undefined reference to `Set_Palette(tagPALETTEENTRY *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2adc):starfe~1.cpp: undefined reference to `Create_BOB(BOB_TYP *, int, int, int, int, int, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2b08):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2b12):starfe~1.cpp: undefined reference to `Load_Frame_BOB(BOB_TYP *, BITMAP_FILE_TAG *, int, int, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2b33):starfe~1.cpp: undefined reference to `Set_Pos_BOB(BOB_TYP *, int, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2b45):starfe~1.cpp: undefined reference to `Set_Anim_Speed_BOB(BOB_TYP *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2b50):starfe~1.cpp: undefined reference to `bitmap8bit'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2b55):starfe~1.cpp: undefined reference to `Unload_Bitmap_File(BITMAP_FILE_TAG *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2b8d):starfe~1.cpp: undefined reference to `screen_width'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2b95):starfe~1.cpp: undefined reference to `screen_height'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2bbe):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2bc4):starfe~1.cpp: undefined reference to `DD_Attach_Clipper(IDirectDrawSurface *, int, tagRECT *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2bce):starfe~1.cpp: undefined reference to `lpddclipper'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2bd6):starfe~1.cpp: undefined reference to `Start_Clock(void)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2c18):starfe~1.cpp: undefined reference to `Destroy_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2c2a):starfe~1.cpp: undefined reference to `DD_Shutdown(void)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2c8d):starfe~1.cpp: undefined reference to `Start_Clock(void)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2ca1):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2ca7):starfe~1.cpp: undefined reference to `DD_Fill_Surface(IDirectDrawSurface *, int)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2e31):starfe~1.cpp: undefined reference to `Animate_BOB(BOB_TYP *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2e8b):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2e96):starfe~1.cpp: undefined reference to `Draw_BOB(BOB_TYP *, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2eb9):starfe~1.cpp: undefined reference to `lpddsback'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2ef1):starfe~1.cpp: undefined reference to `Draw_Text_GDI(char *, int, int, unsigned long, IDirectDrawSurface *)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2f1c):starfe~1.cpp: undefined reference to `DD_Flip(void)'
C:\WINDOWS\TEMP\ccrTbcgb.o(.text+0x2f26):starfe~1.cpp: undefined reference to `Wait_Clock(unsigned long)'



Is the code just too old?
It is from an old book.
It says no errors. But comes up with that though

[edited by - kasooi on July 7, 2003 3:05:33 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by drarem
sounds like dev-c++ to me =)


Sounds like a standard compliant compiler to me (in case you wanted to imply that it is a dev-c++/gcc only thing). VC6 indeed accepts it, and that''s a bug. It has been corrected in VC7.

Share this post


Link to post
Share on other sites
Yeah, you'' need to include int index for your second for loop. The reason is once you''re first for loop is done, variables created in that loop goes out of scope. Thus when you use it again in your function it needs to be defined again. The other option is you can just define int index at the beginning of your function. Then you can use index for whatever you want in the loop without having to redefine it.





You fight like a dairy farmer.

Share this post


Link to post
Share on other sites