Skip to main content
GameDev.net gamedev.net
🔒 Locked

creating a constant string table...

Started by alnite Nov 29, 2002 at 12:11 AM 3 replies 250+ views
Original Post
alnite
alnite
I want to make a list of string and values, similar to map. However, I want it to be constants, so it''s like this: = GetKeyPressed(); cout << "The key you pressed :" << some_var_of_some_type.string << endl; Output: The key you pressed: SPACEBAR The key you pressed: NUMPAD_1 The key you pressed: U The key you pressed: LEFT_SHIFT The key you pressed: NUMPAD_1 there is a loop in GetKeyPressed(). In each iteration, it reads if a key on keyboard/mouse/joystick is pressed. However, each key value has its own string value. I don''t want to use string table resource because I want this to be reusable and not project-dependent. My brain is in dumb state, I know it''s such a simple problem, but I don''t know why I can''t figure it out. Thanks in advance.
My compiler generates one error message: "does not compile."
Evil Bill
Evil Bill

  
const char* g_szKeys[256] = {
"A",
"B",
...,
};

Where the string maps to whatever key you press (e.g if you''re using DirectInput, map it so that g_szKeys[DIK_A] == "A".

HTH

Member of the Unban Mindwipe Society (UMWS)
civguy
civguy
I don''t know how high values those GetKeyPressed()-things return, so array might not be the best choice. Why not use a hash_map, hide it within a class and initialize it in the constructor? Then it looks constant to clients, because they have no means of manipulating it.
Evil Bill
Evil Bill
Its very unlikely that it''ll go over 256. Most keyboard interface things (e.g. DirectInput), only allow a max of 256 keys (even for non-qwerty keyboards). Most keyboards have - i think - 101 or 102 keys. Someone correct me if i''m wrong.

But yeah, you could use a hash_map too.
Member of the Unban Mindwipe Society (UMWS)
alnite
alnite
thanks for the input evil bill and civguy. i want to make it simple, so i think i''ll follow what evil bill suggests.


My compiler generates one error message: "does not compile."

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.