Sign in to follow this  
wraith811

error 2059: syntax error: '='

Recommended Posts

I get about seven of these errors when I compile this program. If someone could point me in the right direction that would be great. The odd thing is that it doesn't point to all the equal signs, the error starts on line 55, 56, 112, 113, 114, 115, and 184. Thanks. /* Beginning Game Programming, Third Edition Chapter 4 Create_Surface Program */ #include <windows.h> #include <d3d9.h> #include <time.h> #include <iostream> using namespace std; //Application title const string APPTITLE = "Create Surface Program"; //Macro to read the keyboard #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) //Screen resolution #define SCREENW = 1024 #define SCREENH = 768 //Direct3D objects LPDIRECT3D9 d3d = NULL; LPDIRECT3DDEVICE9 d3ddev = NULL; LPDIRECT3DSURFACE9 backbuffer = NULL; LPDIRECT3DSURFACE9 surface = NULL; bool gameover = false; /** **Game initialization function **/ bool Game_Init(HWND hwnd) { //Initialize Direct3D d3d = Direct3DCreate9(D3D_SDK_VERSION); if(d3d == NULL) { MessageBox(hwnd, "Error initializing Direct3D", "Error", MB_OK); return false; } //Set Direct3D presentation parameters D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; First error: ***d3dpp.BackBufferWidth = SCREENW;*** Second error: ***d3dpp.BackBufferHeight = SCREENH;*** d3dpp.hDeviceWindow = hwnd; //Create Direct3D device d3d -> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); if(!d3ddev) { MessageBox(hwnd, "Error creating Direct3D device", "Error", MB_OK); return false; } //Set random number seed srand((unsigned int)time(NULL)); //Clear the backbuffer to black d3ddev -> Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); //Create pointer to the backbuffer d3ddev -> GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); //Create surface HRESULT result = d3ddev -> CreateOffscreenPlainSurface( 100, //Width of the surface 100, //Height of the surface D3DFMT_X8R8G8B8, //Surface format D3DPOOL_DEFAULT, //Memory pool to use &surface, //Pointer to the surface NULL); //Reserved (always NULL) if(!SUCCEEDED(result)) return false; return true; } /** **Game update function **/ void Game_Run(HWND hwnd) { //Make sure the Direct3D device is valid if(!d3ddev) return; //Start rendering if(d3ddev -> BeginScene()) { //Fill the surface with random color int r = rand() % 255; int g = rand() % 255; int b = rand() % 255; d3ddev -> ColorFill(surface, NULL, D3DCOLOR_XRGB(r, g, b)); //Copy the surface to the backbuffer RECT rect; Third error: ***rect.left = rand() % SCREENW/2;*** Fourth error: ***rect.right = rect.left + rand() % SCREENW/2;*** Fifth error: ***rect.top = rand() % SCREENH;*** Sixth error: ***rect.bottom = rect.top + rand() % SCREENH/2;*** d3ddev -> StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE); //Stop rendering d3ddev -> EndScene(); //Display the backbuffer on the screen d3ddev -> Present(NULL, NULL, NULL, NULL); } //Check for escape key(to exit program) if(KEY_DOWN(VK_ESCAPE)) PostMessage(hwnd, WM_DESTROY, 0, 0); } /** **Game shutdown function **/ void Game_End(HWND hwnd) { //Free memory if(surface)surface -> Release(); if(d3ddev) d3ddev -> Release(); if(d3d) d3d -> Release(); } /** **Windows event callback function **/ LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_DESTROY: gameover = true; PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); } /** **Main Windows entry function **/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //Create the window class structure WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = APPTITLE.c_str(); wc.hIconSm = NULL; RegisterClassEx(&wc); //Create a new window HWND window = CreateWindow(APPTITLE.c_str(), APPTITLE.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, Seventh error: ***SCREENW, SCREENH, NULL, NULL, hInstance, NULL);*** //Was there an error creating the window? if(window == 0) return 0; //Display the window ShowWindow(window, nCmdShow); UpdateWindow(window); //Initializate the game if(!Game_Init(window)) return 0; //Main message loop MSG message; while(!gameover) { if(PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&message); DispatchMessage(&message); } Game_Run(window); } return message.wParam; }

Share this post


Link to post
Share on other sites
I thought of a different method of showing the lines:

First error:
d3dpp.BackBufferWidth = SCREENW;

Second error:
d3dpp.BackBufferHeight = SCREENH;

Third error:
rect.left = rand() % SCREENW/2;

Fourth error:
rect.right = rect.left + rand() % SCREENW/2;

Fifth error:
rect.top = rand() % SCREENH;

Sixth error:
rect.bottom = rect.top + rand() % SCREENH/2;

Seventh error:
HWND window = CreateWindow(APPTITLE.c_str(), APPTITLE.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
SCREENW, SCREENH, NULL, NULL, hInstance, NULL);

Share this post


Link to post
Share on other sites
Quote:
//Screen resolution
#define SCREENW = 1024
#define SCREENH = 768


These should be:

//Screen resolution
#define SCREENW 1024
#define SCREENH 768





In your current code, wherever the word SCREENW is found in your code, it is replaced with "= 1024" (without quotes), which is giving you the "=" syntax error.

For example:
//d3dpp.BackBufferWidth = SCREENW; becomes
d3dpp.BackBufferWidth = = 1024; //Syntax error "="
//after the preprocessor has replaced SCREENW and SCREENH with "= 1024" and "= 768" respectively.




In any case, #define is generally bad practice (#define is deprecated in the c++ standard I think). Instead I would recommend the use of constants. The best thing to do is to replace the two #define lines with
const int SCREENW = 1024;
const int SCREENH = 768;




Constants are type enforced so the compiler will complain if they are being used inappropriately, avoiding confusion such as the issue you got using defines which simply replace code before compilation.

Hope this helps :)

Share this post


Link to post
Share on other sites
Merry Christmas to you too :)

Just so you know, to make it easier to read your code you should enclose all source code in source tags.

Basically:
[sauce lang="cpp"]
//sauce should actually be spelt "source" obviously lol
int main(){return 0;}
[/sauce]

Or you can check out the forum FAQ (link in top right corner of screen) for a far better explanation :P

Cheers

[Edited by - chrisparton1991 on December 23, 2009 5:57:38 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by chrisparton1991
Merry Christmas to you to :)

Just so you know, to make it easier to read your code you should enclose all source code in source tags.

Basically:
[sauce lang="cpp"]
//sauce should actually be spelt "source" obviously lol
int main(){return 0;}
[/sauce]

Or you can check out the forum FAQ (link in top right corner of screen) for a far better explanation :P

Cheers



Okay, thanks for the input!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this