• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# 03.01 - Q&A

## 120 posts in this topic

The ternary operator is also often used a kinda assignment operator, hence:

x = (bClear == true) ? 0 : 100;

which will set x to either 0 or 100 depending on bClear

---------------------------------------------------
Life after death? No thanks, I want to live NOW
--- Sturm 2001
0

##### Share on other sites
Hi, I want to know what this means:

.... (void **) duh...

Why the two *... what diference this makes?
It´s declarating the type of the variable duh isn´t?
I just wonder what it is!!! thank´s!! bye!
0

##### Share on other sites
I''ve just posted an article in Selected C Topics that deals with pointers, and consequently, **.

Either one of two things will happen; either you''ll come away with a better understanding, or end up worse-off than before you read it

Teej

0

##### Share on other sites
I''m trying to add a menu to my game and am having trouble doing it. I only know how to put up menus with the MFC libraries, which I know are a no no on games. I could do it by having each menu a bitmap, but that would eat up my VRAM. .. so I''m left with trying to find out how to do regular menus. In my game programming book, the author mentioned something about an IDE editor. I have no clue what that is. If someone could give me some direction, I''d really appreciate it. Thanks.

--Vic--
0

##### Share on other sites
Well, I''ve been following this forum, and have looked at multiple other forums on here and have come to the basic conclusion that my c skills aren''t anywhere near good enough to think about games right now. I guess all I''m looking for here is some direction on where to start...I have sam''s teach yourself c++ in 24 hours, and the immortal "Tips and tricks of the windows game programming guru''s", and some other reference books. I figured I would start out with the sam''s book and work my way through. I was wondering if I should maybe start out with a text based game or something, in order to hone my skills...if anyone has any suggestions on stuff that helped them get here, I''m all ears. Thanks for all your help.

0

##### Share on other sites
Teej''s profile:
------------------------------------
Get to know Teej...
Full Name Tim Boston
Nickname Teej
blah blah.....
Contributions to the Site
>>>No Contributions have yet been made to Gamedev.net
-----------------------------------------------

If not like this, How can you contribute to the site than I am curios?
By the way Teej I live in Ontario too. Haha!
Are you by any chance Ukrainian?(just asking)

-SKULLZ
0

##### Share on other sites
Hey Teej, i am from Quebec. We are supposed to hate each other... ;D (politics, what a waste of time anyway)

Hey J_COCHRAN, take the advice from WEATHERMAN:

---------------------------------------------------------------
"Thinking in C++" 2nd edition (volumes 1 and 2) by Bruce Eckel.
These books are available from www.mindview.net (click on "books").

I guarantee that you won''t find a better value than this.

---------------------------------------------------------------

I agree with him. I did a bit of C long time ago and i forgot everything. I use that book to start up again and i am only to the final exercices of chapter 6 (of 16, book 1 of 2) and i''m suprised to be able to follow whitout being totaly overwhelm. Take a look at it, it''s free. You have nothing to loose.

My question: If i want to find a class that does a specific action (ex: get the system clock, performe a mathematical calculation, etc...). Where do i start to look to see if it''s been already written? And once i found it, how do i know what header file to include to make shure it works?

Thanks to anyone.

Lancelot

Life is endlessly short.
0

##### Share on other sites
SKULLZ: I think someone at GDN was watching...it doesn''t say that any longer

Lancelot du lac: Canada, Quebec, English, French... bah humbug.

If you need to do something that requires the assistance of the operating system, it will already be available. By far the ultimate resource for finding out what''s at your disposal when programming is the MSDN library... go to the Index tab and type away -- you''ll always find interesting and pertanent information.

If you''re asking about classes specifically, start at the Microsoft Foundation Classes overview (MFC). If it''s related to Windows, it''s in there, not to mention convenience classes for many other areas of Win32 programming.

Other than that, well, experience prevails.

Teej
0

##### Share on other sites
It is always a long journey to get from no experience to great experience. But, i don''t see a better place to start then here and now.

Thanks Teej for the infos.

Lancelot

Life is endlessly short.
0

##### Share on other sites
Would anybody have any idea why when I hold down the up arrow key and the left arrow key, certain other keys don''t seem to register? Other key combinations seem to cause this type of thing to happen in my program, but I can''t see any reason for it.

Also, I''m having trouble with some class stuff in c++. I have created a class called Sprite, and I created a member function that will take in another member of the class sprite and then check to see if the calling sprite''s bullet has hit the passed in sprite. Here''s the problem, I wanted to create an array of Sprites (so that the number of sprites created is easily managed with a define statment) but that caused my old member function to crash the program. I need to be able to change the data in the Sprite array member being passed in. I''m not sure what I should do, so any help would be greatly appreciated.
0

##### Share on other sites
I have the same problem, when I am using both the right arrow key and the up or down I can''t use the space bar and so on, but it only happens on my laptop, not on my desktop. I think it has something to do with the way your computer reads in the keys, it can''t respond to certain combinations. But I am just guessing Does anyone have a better explanation?

"Fall seven times, stand up eight."
-Japanese Proverb
0

##### Share on other sites
I don''t have an explanation but I was having the same problem with detecting the space key when i was pushing two arrow keys. I tried hooking up a different keyboard and everything worked perfectly. So I''m assuming it does have something to do with the hardware, either that''s the way it was designed or it''s broken.
0

##### Share on other sites
Ok, I had the whole G thing and the struct figured out until I went back and looked at it again a hundredth time.

#ifndef GLOBALS_OWNERSHIP
extern
#endif
blah blah blah

I thought that the usual way this worked was (with headers).
End if

But in the above snippet, I see in GameMain where Globals_Ownership is defined with #define GLOBALS_OWNERSHIP

So why doesn''t the above code say...
if not defined Globals_ownership (which it already is)
extern the following struct
end if
...and then skip over the extern keyword?

Or am I looking at this backwards? Is this code forcing everything to extern G until Game Main gets called and then it is defined? But what keeps the compiler from looking at GameMain until last if this is the case?
0

##### Share on other sites
Nevermind the last post. I understand it again after re-reading the post in 3.03.

Thanks.
0

##### Share on other sites
HELP!! I am about to kill my computer. I am trying to put all the code for making sprites into a class, and in doing so I have set up some static member variables to hold the details that are consistant like the height and width of the sprite. The code looks something like this.

class sprite
{...
public:
static int height;
static int width;
static int movementRate;
...
};

There are some functions and stuff but this is all thats important. The file compiles fine but it dies on the linker. I get a whole lot of errors like:
sprite.obj: error LNK2001: unresolved external symbol "public: static int sprite::height" (?height@sprite@@2HA)

I can''t figure out why. Any suggestions would be welcome.

"Fall seven times, stand up eight."
-Japanese Proverb
0

##### Share on other sites
quote:
Original post by Ible

HELP!! I am about to kill my computer. I am trying to put all the code for making sprites into a class, and in doing so I have set up some static member variables to hold the details that are consistant like the height and width of the sprite. The code looks something like this.

Try giving your statics a value when you declare them in the class. Ie:
  class sprite{...public:static int height = 32;static int width = 32;static int movementRate = 5;...};

-------
Andrew
0

##### Share on other sites
Alas no luck, that gives me a "illegal pure syntax" error. Thanks though. I think I might just give up on making the members static for now. It will be far less efficient but that isn't really a concern yet

Edit: I got it! Thanks to whoever recommended Thinking in C++, that book did the trick, for free no less. I'll get this thing up and running yet!

"Fall seven times, stand up eight."
-Japanese Proverb

Edited by - Ible on June 9, 2001 3:48:11 AM
0

##### Share on other sites
Ible... what solution did you use? I had a similar problem and I just gave up on that aspect, and made each object static instead of their variables.
0

##### Share on other sites
a static class member is where one variable is used for every object of that class. You must actually create an instance of each of the static variables globally, since a new instance is not created when you create an object of the class.
0

##### Share on other sites
Ible:

quote:

HELP!! I am about to kill my computer. I am trying to put all the code for making sprites into a class, and in doing so I have set up some static member variables to hold the details that are consistant like the height and width of the sprite. The code looks something like this.

class sprite
{...
public:
static int height;
static int width;
static int movementRate;
...
};

There are some functions and stuff but this is all thats important. The file compiles fine but it dies on the linker. I get a whole lot of errors like:
sprite.obj: error LNK2001: unresolved external symbol "public: static int sprite::height" (?height@sprite@@2HA)

You can't initialize a static data member inside the class declaration. Remember that the class declaration only describes the class - it doesn't actually allocate any memory.

You should allocate memory for the static member with a statement in the file that contains the definitions of the class methods. You should also use the scope resolution operator :: to tell the computer which class the member belongs to.

In your example, you could have the following statements in your definitions file (if you were to put these statements in your header file, you would probably get a lot of linker errors saying that you have multiple definitions):

int sprite::height = 32;
int sprite::width = 32;
int sprite::movementRate = 100;

(use whatever values make sense to you).

Edited by - Weatherman on June 10, 2001 11:49:10 AM
0

##### Share on other sites
There''s a little bit of code that I''ve added to my GameMain() and for some reason I''m getting wierd results.

if (KEYDOWN(DIK_M))
{
ShowCursor(TRUE);
MessageBox(G.hWnd, "Work", "Work all day", MB_OK);
}

Originally in the WinMain the ShowCursor was set to FALSE. I''m expecting this to create a Message box which the user can then click on with the mouse to make it disappear. However, when I press ''M'', the program freezes as expected, but sometimes the message box doesn''t appear. At that point, the only way to get the GameMain() function to continue is by pressing ESC. What can I do to get my messagebox to show up all the time?

0

##### Share on other sites
I have a question about the executable. I entered the code from one the examples in 4.03 (the random expanding squares) it runs from within the IDE and I would like to take the .exe and put it on another computer to use as a screen saver. First however, I tried to run the .exe from Windows Explorer on the computer which the code was entered and compiled on and I get DD_Init Failed: -7 DirectX Intialisation Error both the debug and release versions.

Can someone tell me how I can compile and distribute the .exe? Even to the computer it was developed on...
0

##### Share on other sites
Yeh, I had this problem myself. I''m using Visual Studio and the executable is placed in a folder named Debug or Release depending on the build, but the error comes up because it cannot find the resources. If you copy the resources to the folder it should work fine.

Hope this helps. Bye
0

##### Share on other sites
Randomgamer: I did the same thing that Weatherman suggests and in the class''s CPP file just before the function definitions i have lines like:
int sprite::width = 31;
int sprite::height = 32;

and so on. I did have one interesting experience though maybe someone could explain to me. I tried to inherit a bullet class from my sprite class i.e.

class bullet : public sprite
{...};

But it seems to have created only one instance of the static member variables, that is there is one width(etc) variable for both sprite and bullet, so sprite::width and bullet::width both access the same thing. Am I doing something wrong or is it supposed to work like that?

"Fall seven times, stand up eight."
-Japanese Proverb
0

##### Share on other sites
Thanks. Copying the resources into the folder fixed the problem.

0