It's not in the code anywhere. C++ just randomly inserts 302 into a referenced local variable, you have to put a new variable above it, u can set the new unused variable to 1000 and it changes to 302 on more than 1 conmputer, with completely different programmers. I really dont think posting code is important, I just thought maybe someone else has seen this. And btw, I was expecting professional answers, not a bunch of jibberish from children, guess it was a mistake to ask an intelligient question here.
void DarkGDK()
{
// Local variables int kp = 1000; // Stops my rocks from going bonkers.
int rocks = MAX_ROCKS; // Number of rocks in play
int caught = 0; // Number of rocks caught
int broken = 0; // Number of rocks broken
int cartX, cartY; // Cart's XY coordinates
int rockX, rockY; // Rocks's XY coordinates
int time = 0; // Time, for distance formula
Here is the code in question, I set my max_rocks at 5 and it changed it to 302 , here is that code....
const int MAX_ROCKS = 5; // Total number of rocks
const int CART_MOVE = 4; // Amount to move the cart
const float ACCELERATION = 0.45; // Gravity acceleration
const int REFRESH_RATE = 60; // Refresh rate
the only way to fix this is to make a new variable (kp = 1000) and put it on top of the other variables, i dont need to know how to fix it, ive done that, i want to know y i had to fix it...thank you very much
If this is happening on most modern operating systems like window, linux or other such systems that handle a multi-tasking system it would cause an error in the OS. The fact that you have repeated it on multiple computers doesn't tell me anything because of this knowledge from a 25 year programmer. If this is happening on DOS box it might be explainable a little more. The number 302 doesn't say anything either, since I don't know anything about the individual machines you reproduced it on. For a more professional answer you going to have to produce code or give further details of how to do it, because this sounds like some one who doesn't know how to ask a question on this board.
Do you have any arrays anywhere in your code?
What is the scope of your const? (File, Global, Local, Member)
When you step through the code when does MAX_ROCKS become 302.
When you step through the code when does MAX_ROCKS NOT equal 302.
Where is MAX_ROCKS declared?
Where is MAX_ROCKS defined?
Is MAX_ROCKS used in non-member non-friend functions?
Is MAX_ROCKS used in member functions?
Is MAX_ROCKS used in templates?
Is there more than one MAX_ROCKS variable in any scope in any file within your project?
Is this Multi-threaded or singly?
The fact that this is repeated on multiple computers tells me this is a programming error (Most likely).
Post the Declaration of MAX_ROCKS.
Post the definition of MAX_ROCKS.
Post the usages of MAX_ROCKS including code before and after, meaning if it is used in a function post the entire function.
I dont know alot but it sure seems like some people on here should learn what the term "help someone out" means, learn how to help people...this seems like a big joke, thanks for nothing...
// Constants for the image numbers
const int TITLE_SCREEN_IMAGE = 1;
const int BACKDROP_IMAGE = 2;
const int ROCK_IMAGE = 3;
const int BROKEN_ROCK_IMAGE = 4;
const int STONEBG_IMAGE = 5;
const int CART_IMAGE = 6;
const int HIT_CART_IMAGE = 7;
const int TRACKS_IMAGE = 8;
// Constants for the sprite numbers
const int STONEBG_SPRITE = 1;
const int CART_SPRITE = 2;
const int ROCK_SPRITE = 3;
const int HIT_CART_SPRITE = 4;
const int BROKEN_ROCK_SPRITE = 5;
const int TRACKS_SPRITE = 6;
// Constants for the sound numbers
const int DOWN_SOUND = 1;
const int CRASH_SOUND = 2;
const int METAL_SOUND = 3;
const int COMPLETE_SOUND = 4;
const int PERFECT_SCORE_SOUND = 5;
// Constants for the music numbers
const int INTRO_MUSIC = 1;
const int MAIN_MUSIC = 2;
// Time delay constants
const int TENTH_SECOND = 100;
const int ONE_SECOND = 1000;
const int FOUR_SECONDS = 4000;
// Other constants
const int MAX_ROCKS = 5; // Total number of rocks
const int CART_MOVE = 4; // Amount to move the cart
const float ACCELERATION = 0.45; // Gravity acceleration
const int REFRESH_RATE = 60; // Refresh rate
// Function Prototypes
void loadResources();
void createSprites(int &, int &, int &, int &);
void intro();
void moveCart(int &);
void moveRock(int &, int &, int &);
void checkCollisions(int, int &, int &, int &, int &, int &);
void showHitCart();
void showBrokenRock();
void resetRock(int, int &);
void render(int, int, int &, int);
void deleteSprites();
void summaryScreen(int, int);
//******************************************
// DarkGDK function *
//******************************************
void DarkGDK()
{
// Local variables
int kp = 1000; // Stops my rocks from going bonkers.
int rocks = MAX_ROCKS; // Number of rocks in play
int caught = 0; // Number of rocks caught
int broken = 0; // Number of rocks broken
int cartX, cartY; // Cart's XY coordinates
int rockX, rockY; // Rocks's XY coordinates
int time = 0; // Time, for distance formula
// Load the game resources.
loadResources();
// Display the title and intro screens.
intro();
dbRandomize( dbTimer() );
// Create the sprites.
createSprites(cartX, cartY, rockX, rockY);
// Execute the game loop.
while ( LoopGDK() && rocks > 0 )
{
// Move the cart.
moveCart(cartX);
// Move the rock.
moveRock(rockX, rockY, time);
// Check for collisions.
checkCollisions(rockY, rockX, caught,
broken, rocks, time);
// Render the scene.
render(cartX, cartY, rockX, rockY);
dbSync();
}
// Display the summary screen.
summaryScreen(caught, broken);
}
// ******************************************************
// The loadResources function loads all the images *
// and audio files. *
// ******************************************************
void loadResources()
{
// Set the color key to green.
dbSetImageColorKey(0, 255, 0);
// ******************************************************
// The intro function displays a title screen, followed *
// by an intro screen while playing music. *
// ******************************************************
void intro()
{
// Set the window title.
dbSetWindowTitle("Catch the Boulder");
// Loop the intro music.
dbLoopMusic(INTRO_MUSIC);
// Paste the title screen image and wait for
// the user to press a key.
dbPasteImage(TITLE_SCREEN_IMAGE, 0, 0);
dbWaitKey();
// Clear the screen.
dbCLS();
// Stop the music.
dbStopMusic(INTRO_MUSIC);
// Disable auto refresh and set the
// refresh rate.
dbSyncOn();
dbSyncRate(REFRESH_RATE);
}
// ******************************************************
// The createSprites function creates the sprites. *
// Parameter summary: *
// cartX: The cart's X coordinate (by reference) *
// cartY: The cart's X coordinate (by reference) *
// rockX: The rock's X coordinate (by reference) *
// rockY: The rock's X coordinate (by reference) *
// ******************************************************
void createSprites(int &cartX, int &cartY, int &rockX,
int &rockY)
{
// Variable to hold calculated sprite numbers.
int spriteNum;
// Hide the hit cart and broken rock sprites.
dbHideSprite(HIT_CART_SPRITE);
dbHideSprite(BROKEN_ROCK_SPRITE);
// Set the starting position of the rock to
// the center of the top of the screen.
rockX = dbScreenWidth() / 2 -
dbSpriteWidth(ROCK_SPRITE) / 2;
rockY = 0;
// Clone the rock sprite to display mini rocks at the
// top of the screen. The cloned mini rocks sprite
// numbers will begin at 100.
for(int count = 0; count < MAX_ROCKS; count++)
{
// Calculate a new sprite number.
spriteNum = 100 + count;
// Clone the rock sprite.
dbCloneSprite(ROCK_SPRITE, spriteNum);
// Scale the sprite to 50%.
dbScaleSprite(spriteNum, 50);
// Place the sprite in the status bar.
dbSprite(spriteNum, dbSpriteWidth(ROCK_SPRITE) / 2 * count , 0, ROCK_IMAGE);
}
}
// *****************************************************
// The moveRock function moves the rock sprite both *
// down the screen and across the screen. *
// Parameter summary: *
// rockX: The rock's X coordinate (by reference) *
// rockY: The rock's Y coordinate (by reference) *
// time: The falling time (by reference) *
// *****************************************************
void moveRock(int &rockX, int &rockY, int &time)
{
// Local varible to hold the falling distance
float distance;
// Calculate the falling distance.
distance = 0.5 * ACCELERATION * time * time;
// update the rock Y position.
rockY = distance + dbSpriteHeight(ROCK_SPRITE) / 2;
// Increment the falling time.
time++;
}
// *****************************************************
// The moveCart function detects keyboard input and *
// moves the cart accordingly. *
// Parameter summary: *
// cartX: The cart's X coordinate (by reference) *
// *****************************************************
void moveCart(int &cartX)
{
// Check if the left key is pressed.
if(dbLeftKey())
{
// Stop the cart at the left edge of the screen.
if (cartX <= 0)
{
cartX = 0;
}
// Move the cart left.
else
{
cartX -= CART_MOVE;
}
}
// Check if the right key is pressed.
if(dbRightKey())
{
// Stop the cart at the right edge of the screen.
if (cartX + dbSpriteWidth(CART_SPRITE) >= dbScreenWidth())
{
cartX = dbScreenWidth() - dbSpriteWidth(CART_SPRITE);
}
// Move the cart right.
else
{
cartX += CART_MOVE;
}
}
}
// *****************************************************
// The checkCollisions function checks for a collision *
// between the rock and cart or the ground. *
// Parameter summary: *
// rockY: The rock's Y coordinate (by reference) *
// caught: The number of caught rocks (by reference) *
// broken: The number of broken rocks (by reference) *
// rocks: The number of rocks in play (by reference)*
// time: The falling time (by reference) *
// *****************************************************
void checkCollisions(int rockY, int &rockX, int &caught,
int &broken, int &rocks, int &time)
{
// The rock has hit the cart.
if ( dbSpriteCollision(ROCK_SPRITE, CART_SPRITE) )
{
// Increment number of caught rocks.
caught++;
// Decrement number of rocks in play.
rocks--;
// Show the hit cart effect.
showHitCart();
// Reset the rock.
resetRock(rocks, rockX);
// Reset the falling time.
time = 0;
}
// The rock has missed the basket.
else if (rockY > dbScreenHeight() )
{
// Increment the number of broken rocks.
broken++;
// Decrement the number of rocks in play.
rocks--;
// Show the broken rock effect.
showBrokenRock();
// Reset the rock.
resetRock(rocks, rockX);
// Reset the falling time.
time = 0;
}
}
//*************************************************
// The showHitCart function displays the hit *
// cart effect and plays the metal sound. *
//*************************************************
void showHitCart()
{
// Temporarily enable auto refresh.
dbSyncOff();
// Show the hit cart sprite.
dbShowSprite(HIT_CART_SPRITE);
// Play the metal ting sound.
dbPlaySound(METAL_SOUND);
// Wait for a tenth of a second.
dbWait(TENTH_SECOND);
// Hide the hit cart sprite.
dbHideSprite(HIT_CART_SPRITE);
// Disable auto refresh.
dbSyncOn();
}
//*************************************************
// The showBrokenRock function displays the broken*
// rock effect and plays the clap sound. *
//*************************************************
void showBrokenRock()
{
// Temporarily enable auto refresh.
dbSyncOff();
// Show the broken rock sprite.
dbShowSprite(BROKEN_ROCK_SPRITE);
// Play the crash sound.
dbPlaySound(CRASH_SOUND);
// Wait for a tenth of a second.
dbWait(TENTH_SECOND);
// Hide the broken rock sprite.
dbHideSprite(BROKEN_ROCK_SPRITE);