Well then they aren't Global variables. Make them before you start the int main() loop. Try that. Read a tutorial please, it will make life more enjoyable.
Could you show us where and how they're defined, and the errors they provide?

Code:
struct Coord cur;   
  cur.x = 128;   
  int w = rand()%(340-45+1) + 45;
  int b = rand()%(340-45+1) + 45;
  int j = 0;
  int s = 0;
while(1) {     
    int key = PRGM_GetKey();     
    if(key == KEY_PRGM_MENU) {  GetKey(&key); }         
    moveCursor(&cur);   
    CopySprite(BulletBackground, 0, 0, 384, 216);
    CopySpriteMasked(SpenBullet, cur.x, 159, 38, 43, COLOR_RED);
    CopySpriteMasked(Banana, w, j, 75, 80, COLOR_RED);
    CopySpriteMasked(LSDOMG, b, j, 34, 34, COLOR_RED);
    if(w == cur.x && j == 159)
    break;
    if(b == cur.x && j == 159)
    s++;
    j+=8;
    if(j > 216) {
  int j = 0;
  int w = rand()%(340-45+1) + 45;
  int b = rand()%(340-45+1) + 45;}
    if(keydown(KEY_PRGM_EXIT)
    break;
    Bdisp_PutDisp_DD();     
    Bdisp_AllCr_VRAM();
  }     }
    if(keydown(KEY_PRGM_SHIFT) && y == 145) {
while(1) {
    CopySprite(Instructions, 0, 0, 384, 216);
    if(keydown(KEY_PRGM_EXIT))
    break;
    Bdisp_PutDisp_DD();     
    Bdisp_AllCr_VRAM();
}
  return 0;
}
    Bdisp_PutDisp_DD();     
    Bdisp_AllCr_VRAM();

}

  return 0;     
}




What it gives me:

Code:
main.c:104:7: warning: unused variable 'b' [-Wunused-variable]
main.c:103:7: warning: unused variable 'w' [-Wunused-variable]
main.c:102:7: warning: unused variable 'j' [-Wunused-variable]
main.c:106:5: error: expected ')' before 'break'
main.c:109:3: error: expected expression before '}' token
make: *** [main.o] Error 1


By the way, I don't see anything about global variables in the tutorial.
Quote:

Code:
if(keydown(KEY_PRGM_EXIT)

Add a parenthesis to the end of that line.
Quote:

Code:
  }     }

I'm not sure what that second brace is supposed to match up with.
Well, you're creating two sets of the b, w, and j variables inside the while loop, effectivly ignoring the higher-scoped ones. If you're just trying to reset those ones instead of making new ones, take the 'int' away from each time you try to feed them new values.
Quote:
By the way, I don't see anything about global variables in the tutorial.

In that case, you should use Google to find out what global variables are. Not everything is going to be explained in a tutorial, and you might have to do a bit of searching to find what you're looking for.
It works now, but the sprites that use the rand get generated every frame. So it looks like are getting jerked around.
What type of effect are you going for then, with their movements?
I'm making an object scroll to the bottom of the screen and when the object hits the bottom, it generates a new one.
Spenceboy98 wrote:
I'm making an object scroll to the bottom of the screen and when the object hits the bottom, it generates a new one.


Then each frame you should check to see if the enemy's y position is at or past a certain point, and if it is, then reset it with the rand function.
I did. It does it still. Here's code:


Code:
int main() {     
  int y = 129;   
  while(1) {     
    int key = PRGM_GetKey();     
    if(key == KEY_PRGM_MENU) {  GetKey(&key); }         
    CopySprite(BulletMenu, 0, 0, 384, 216);
    CopySpriteMasked(BulletMenuSelector, 7, y, 18, 16, COLOR_RED);
    if(keydown(KEY_PRGM_UP) && y>129)
    y-=16;
    if(keydown(KEY_PRGM_DOWN) && y<145)
    y+=16;
    if(keydown(KEY_PRGM_SHIFT) && y == 129) {
while(1) {     
  struct Coord cur;   
  cur.x = 128;   
  int w = rand()%(340-45+1) + 45;
  int b = rand()%(340-45+1) + 45;
  int j = 0;
  int s = 0;
    int key = PRGM_GetKey();     
    if(key == KEY_PRGM_MENU) {  GetKey(&key); }         
    moveCursor(&cur);   
    CopySprite(BulletBackground, 0, 0, 384, 216);
    CopySpriteMasked(SpenBullet, cur.x, 159, 38, 43, COLOR_RED);
    CopySpriteMasked(Banana, w, j, 75, 80, COLOR_RED);
    CopySpriteMasked(LSDOMG, b, j, 34, 34, COLOR_RED);
    if(w == cur.x && j == 159)
    break;
    if(b == cur.x && j == 159)
    s++;
    j+=8;
    if(j < 216) {
  j = 0;
  w = rand()%(340-45+1) + 45;
  b = rand()%(340-45+1) + 45;}
    if(keydown(KEY_PRGM_EXIT))
    break;
    Bdisp_PutDisp_DD();     
    Bdisp_AllCr_VRAM();
  }     }
    if(keydown(KEY_PRGM_SHIFT) && y == 145) {
while(1) {
    CopySprite(Instructions, 0, 0, 384, 216);
    if(keydown(KEY_PRGM_EXIT))
    break;
    Bdisp_PutDisp_DD();     
    Bdisp_AllCr_VRAM();
}
  return 0;
}
    Bdisp_PutDisp_DD();     
    Bdisp_AllCr_VRAM();

}

  return 0;     
}
I'm not sure if I'm allowed to help you with your contest entry to the point of writing some code for you, but I can make one suggestion so that I can make some points about why it might not be working: I can hardly read that code. Perhaps tab it in correctly, and use curly bracket blocks for if-statements when possible?
Spenceboy98 wrote:
I tried that. It didn't work. It said that the variables I reset were unused.
That's a warning that means you're not actually using the variable for anything anywhere. It sounds like you really need to read a C tutorial or two.
I don't know how to tab it. This is so frustrating!
Spenceboy98 wrote:
I don't know how to tab it. This is so frustrating!

"Tabbing" your code means to indent it so that code at the same "level" is indented by the same amount. For example, the top-level code (eg, #includes and function definitions) should not be indented at all. See http://en.wikipedia.org/wiki/Indent_style for some simple indentation style "rules". There are a few popular different styles, but whichever you use, stick with it. Remember, source code should be readable by humans, and consistency helps.

Any decent text editor (which automatically excludes Notepad) makes it easy to indent your code. I personally use vim and occasionally gedit, but IIRC, you're stuck with Windows, so other people can suggest good text editors that will run (more natively) in Windows.
^ indeed, there is Vim for windows too, but I think that Notepad++ is a great Windows text editor. Some argue Programmers Notepad is a better substitute, but it's hard to go wrong with either one, in my opinion.
I just tried Kerms input code by itself, but it says,


Code:
main.c: In function 'getTextLine':
main.c:13:2: warning: implicit declaration of function 'RTC_GetTicks' [-Wimplici
t-function-declaration]
main.c:51:3: warning: implicit declaration of function 'PrintXY' [-Wimplicit-fun
ction-declaration]
main.c:58:4: warning: implicit declaration of function 'GetKeyWait_OS' [-Wimplic
it-function-declaration]
main.c:59:4: warning: implicit declaration of function 'Bdisp_EnableColor' [-Wim
plicit-function-declaration]
main.c:89:23: error: 'KEY_PRGM_DEL' undeclared (first use in this function)
main.c:89:23: note: each undeclared identifier is reported only once for each fu
nction it appears in
main.c:109:8: warning: implicit declaration of function '_g_strlen' [-Wimplicit-
function-declaration]
main.c: In function 'DrawCursor':
main.c:188:4: warning: implicit declaration of function 'Bdisp_PutDisp_DD' [-Wim
plicit-function-declaration]
make: *** [main.o] Error 1


What did I do wrong?
The only error you have is " 'KEY_PRGM_DEL' undeclared " cause you haven't include the header which define KEY_PRGM_DEL. Search in the PrizmSDK-0.3/include directory, and include the header you need.

All "warning: implicit declaration of function" are also cause you haven't include the right headers.

If you say to a friend to call Bob without giving him Bob's number, your friend can't call him. It's exactly the same for a compiler.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 4 of 4
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement