WH8 that doesn't make sense
The code shown below causes an access violation:
// Delete all sprites
void delsprite(void)
{
for (int d=0;d<=500;d++)
{
if (dbSpriteExist(d))dbDeleteSprite(d);
}
}
This is becuase you cant have object 0, only object 1. Changing the code to this fixes the problem:
// Delete all sprites
void delsprite(void)
{
for (int d=1;d<=500;d++)
{
if (dbSpriteExist(d))dbDeleteSprite(d);
}
}
Same with the delmusic, delimage and delall functions
Fixed code:
#include "DarkGDK.h"
int ArrowKeyHL = 0;
int keystillpressed = 0;
// Delete all images
void delimage(void)
{
for (int d=1;d<=500;d++)
{
if (dbImageExist(d))dbDeleteImage(d);
}
}
// Delete all sprites
void delsprite(void)
{
for (int d=1;d<=500;d++)
{
if (dbSpriteExist(d))dbDeleteSprite(d);
}
}
// Delete all music
void delmusic(void)
{
for (int d=1;d<=500;d++)
{
if (dbMusicExist(d))dbDeleteMusic(d);
}
}
// Delete all
void delall(void)
{
for (int d=1;d<=500;d++)
{
if (dbMusicExist(d))dbDeleteMusic(d);
if (dbSpriteExist(d))dbDeleteSprite(d);
if (dbImageExist(d))dbDeleteImage(d);
}
}
// Click button
// Mouse and arrow key button highlight
// Mouse click and enter key select
int clickbutton(int spritestart,int spriteend)
{
int MouseHL = 0,sb=0,ButtonHL=0;
for (sb=spritestart;sb<=spriteend;sb++)
{
if (dbMouseX() >=dbSpriteX(sb) && dbMouseX() <=dbSpriteX(sb) + dbSpriteWidth(sb) && dbMouseY()>=dbSpriteY(sb) && dbMouseY()<=dbSpriteY(sb)+dbSpriteHeight(sb))
{
MouseHL = sb;
}
if(dbSpriteExist(sb+100))dbDeleteSprite(sb+100);
}
if (!MouseHL)
{
if (dbDownKey()&& !keystillpressed)ArrowKeyHL++;
if (dbUpKey()&& !keystillpressed)ArrowKeyHL--;
if (dbDownKey() && ArrowKeyHL >=(spriteend-19)&& !keystillpressed)ArrowKeyHL=1;
if (dbUpKey() && ArrowKeyHL <=0 && !keystillpressed)ArrowKeyHL=(spriteend-20);
keystillpressed=dbScanCode();
}
if (MouseHL){ButtonHL=MouseHL;ArrowKeyHL=0;}
if(ArrowKeyHL)ButtonHL=(ArrowKeyHL+20);
dbSprite((ButtonHL+100),dbSpriteX(ButtonHL),dbSpriteY(ButtonHL),(ButtonHL+100));
if (dbMouseClick() || dbReturnKey())return ButtonHL;
return 0;
}
For some reason when built in debug mode it doesn't pick up this error