Dark Gdk Noob Question

Started by
2 comments, last by Zahlman 14 years, 8 months ago
Well I was just starting Dark GDK and I wanted to place the cursor in the middle of the screen. I tried making a variable that would contain the Height of the screen / 2 and the Width of the screen / 2. Heres my code: #include "DarkGDK.h" int ScreenHeightHalf = dbScreenHeight / 2; void DarkGDK ( void ) { dbSyncOn ( ); dbSyncRate ( 60 ); while ( LoopGDK ( ) ) { dbSetCursor ( 1 , 1 ); dbSync ( ); } return; } (Ignore the fact that dbSetCursor is 1, 1, I just input that to check for errors) My Problem is at the top under the Include DarkGDK. That int Var is giving me the error: '/' : illegal, left operand has type 'int (__cdecl *)(void)' I am a beginner at Dark GDK so I have no clue what I just did wrong. Can anyone explain what I'm doing wrong here? Also, Sorry if this is in the wrong section.
Advertisement
There get screen width is a function and should be:
get screenwidth().

Functions need ().

Not sure if this is right but i think it is....

PureBlackSin
For Games, Articles and Custom High End Computers, come visit.Myndoko
either move your variable inside your DarkGDK function or declare it as const.

Values assigned to global variables must be known at compile time, so you can't assign the value of another variable.

hope that helps
Quote:Original post by Dragon_Lance
int ScreenHeightHalf = dbScreenHeight / 2;

'/' : illegal, left operand has type 'int (__cdecl *)(void)'


Learn to read error messages.

The message says that there is a problem with the "/" because the "left operand" is a "int (__cdecl *)(void)".

You can find the "/" easily. An "operand" is one of the values operated upon by an operator (in this case, the division operator). The "left operand" is of course the one that's on the left-hand size of a binary operator, in this case, 'dbScreenHeight'.

So we are told that 'dbScreenHeight' is an "int (__cdecl *)(void)". In general, types that look like "{type} ({possibly something here} *)({type})" are function types. The middle part specifies calling conventions ("__cdecl" means an ordinary C-style function; "__thiscall" and "{class name}::" are for member functions) and the rest looks like the stuff you would find on either side of the function name in its declaration. So we have a function that was declared "int dbScreenHeight(void)", i.e. it takes no arguments and returns an int.

We can't divide a function by 2. However, the function returns an int when called, and we can divide an int by 2. It seems likely that the solution is to call the function - thus, dbScreenHeight(), since it takes no arguments. (If it took arguments, you would have to figure out what values to pass.)

Quote:Original post by matchu
either move your variable inside your DarkGDK function or declare it as const.

Values assigned to global variables must be known at compile time, so you can't assign the value of another variable.

hope that helps


This is not correct and has nothing to do with the cited error message anyway.

You cannot assign to a global variable at all outside of function scope. In fact, you can't execute any code outside of function scope in C++ at all. But you can initialize global variables, even with runtime values - you just may have to be careful about order of initialization.

This topic is closed to new replies.

Advertisement