Hey guys,
I'm fairly new to C++ (just started seriously looking into it a couple of months ago), and I thought that using DGDK would be a good way to get even more serious with it. I seem to be having trouble with variables. Variables! Something as simple as that.
Here's my code...
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSetDisplayMode(960,720,32);
dbSetWindowSize(960,720);
dbSetWindowPosition(0,0);
dbSetWindowTitle("Main Screen");
dbSetTextFont("microsoft sans serif");
dbSetTextSize(12);
dbSyncOn ( );
dbSyncRate ( 60 );
// our main loop
while ( LoopGDK ( ) )
{
dbCLS(dbRGB(0,0,0));
//create a box
dbBox(dbScreenWidth()/2-122,dbScreenHeight()/2-50,dbScreenWidth()/2+122,dbScreenHeight()/2-30,dbRGB(15,15,15),dbRGB(55,55,55),dbRGB(15,15,15),dbRGB(55,55,55));
//check for mouse hovering and clicking
if (dbMouseX() > dbScreenWidth()/2-122 && dbMouseY() > dbScreenHeight()/2-50 && dbMouseX() < dbScreenWidth()/2+122 && dbMouseY() < dbScreenHeight()/2-30 && dbMouseClick()==1)
{
dbCenterText(dbScreenWidth()/2,dbScreenHeight()-15,"This has been clicked");
dbBox(dbScreenWidth()/2-123,dbScreenHeight()/2-51,dbScreenWidth()/2+123,dbScreenHeight()/2-29,dbRGB(255,255,255),dbRGB(255,255,255),dbRGB(255,255,255),dbRGB(255,255,255));
dbBox(dbScreenWidth()/2-122,dbScreenHeight()/2-50,dbScreenWidth()/2+122,dbScreenHeight()/2-30,dbRGB(55,55,55),dbRGB(15,15,15),dbRGB(55,55,55),dbRGB(15,15,15));
}
if (dbMouseClick()==2)
{
int bActive=1;
int OldMouseX=dbMouseX();
int OldMouseY=dbMouseY();
if (bActive==1)
{
dbBox(OldMouseX,OldMouseY,OldMouseX+250,OldMouseY+300,dbRGB(55,55,55),dbRGB(15,15,15),dbRGB(55,55,55),dbRGB(15,15,15));
dbText(OldMouseX+5,OldMouseY+15,"You clicked!");
if (dbMouseClick()==1 && bActive==1) {bActive=0;break;}
}
}
// update the screen
dbSync ( );
}
// return back to windows
return;
}
Here's the part I'm having trouble with:
if (dbMouseClick()==2)
{
int bActive=1;
int OldMouseX=dbMouseX();
int OldMouseY=dbMouseY();
if (bActive==1)
{
dbBox(OldMouseX,OldMouseY,OldMouseX+250,OldMouseY+300,dbRGB(55,55,55),dbRGB(15,15,15),dbRGB(55,55,55),dbRGB(15,15,15));
dbText(OldMouseX+5,OldMouseY+15,"You clicked!");
if (dbMouseClick()==1 && bActive==1) {bActive=0;break;}
}
}
What I want to do is make it so that if the user right-clicks anywhere in the program, a "menu" appears at the old mouse positions, but I can only achieve this if the user holds the mouse button down. I thought that by adding the variable "bActive" would fix this, but I encountered an error that said "bActive is not declared in this scope", and I found out the only way I could use it was if I included it in the dbMouseClick==2 code block, but that totally defeats the purpose of even creating it and it doesn't even work!
I have no idea how to make variables global. I tried what's outlined in
this page but it didn't work. What am I doing wrong? What do I need to do?
Thanks for any and all help,
-CoffeeCoder