Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Estaog on Wed 16/06/2004 09:40:35

Title: Keycode Problem
Post by: Estaog on Wed 16/06/2004 09:40:35
I did this code in the global script so it will be like monkey island when you press f1 the quit gui comes up.But nothing seems to happen. Help?

if (b==0) keycode=0;
if (b==1) keycode=1;
if (keycode==359) GUIOn (1);
Title: Re: Keycode Problem
Post by: Gilbert on Wed 16/06/2004 09:45:13
Did you put it in the on_key_press() function?
Title: Re: Keycode Problem
Post by: strazer on Wed 16/06/2004 10:24:26
What is the variable b for?

If it can only be either 0 or 1 then

  if (keycode==359) GUIOn (1);

would never be true since you reset the keycode variable in both instances.
Title: Re: Keycode Problem
Post by: Paper Carnival on Wed 16/06/2004 11:09:59
or, if you really want to do it that way, try this instead:

if (keycode==359) GUIOn (1);
if (b==0) keycode=0;
if (b==1) keycode=1;
Title: Re: Keycode Problem
Post by: Estaog on Wed 16/06/2004 17:40:35
I put this code in my Repeatedly execute part:
on_key_press (359) { GUIOn (1)}
And its saying unidentified token when saving, what is the deal?
Title: Re: Keycode Problem
Post by: Barbarian on Wed 16/06/2004 18:00:57
Try putting under the part of the global script that has:

"function on_key_press(int keycode)"

And I tested to see if I could use my F1 key to open up my inventory GUI and it worked fine. I added the following command:

if (keycode==359) {GUIOn(INVENTORY);}

Ã,  Ã, You could probably do something similar to enable your GUI? Instead of using the specific GUI number (as I know that can change sometimes according to how you program things), use the GUI name instead perhaps, so regardless of the GUI number, the name of a GUI should still be associated with it. Well, either way should work fine I guess?Ã,  ;)

*Edit:  If you just want to bring up the default Quit GUI when you press the F1 key, then I think it would be:

if (keycode==359) {QuitGame(1); }
Title: Re: Keycode Problem
Post by: Estaog on Thu 17/06/2004 09:30:19
Actually i did use that. But i did something that allowed you only to bring it up from room 2, removed it, and i still cant bring it up in room 1. It just flashes when i press f1. Any ideas?
Title: Re: Keycode Problem
Post by: Radiant on Thu 17/06/2004 11:41:04
Show us your code please? You probably didn't remove it properly, I'd guess
Title: Re: Keycode Problem
Post by: Estaog on Thu 17/06/2004 13:24:50
function on_key_press(int keycode) {
  // called when a key is pressed. keycode holds the key's ASCII code
  if (IsGamePaused() == 1) keycode=0;  // game paused, so don't react to keypresses
  if (keycode==359) GUIOn (1);
  if (keycode==434) SaveScreenShot("scrnshot.bmp");  // F12
  if (keycode==19)  Debug(0,0);  // Ctrl-S, give all inventory
  if (keycode==22)  Debug(1,0);  // Ctrl-V, version
  if (keycode==1)   Debug(2,0);  // Ctrl-A, show walkable areas
  if (keycode==24)  Debug(3,0);  // Ctrl-X, teleport to room
}

There used to be something that said if b==1 keycode=0, but removed it and its still flashing in room 1. I cant understand why. Maybe you know.
Title: Re: Keycode Problem
Post by: Barbarian on Thu 17/06/2004 13:53:22
Quote from: Tanker on Thu 17/06/2004 13:24:50
function on_key_press(int keycode) {
Ã,  // called when a key is pressed. keycode holds the key's ASCII code
Ã,  if (IsGamePaused() == 1) keycode=0;Ã,  // game paused, so don't react to keypresses
Ã,  if (keycode==359) GUIOn (1);
Ã,  if (keycode==434) SaveScreenShot("scrnshot.bmp");Ã,  // F12
Ã,  if (keycode==19)Ã,  Debug(0,0);Ã,  // Ctrl-S, give all inventory
Ã,  if (keycode==22)Ã,  Debug(1,0);Ã,  // Ctrl-V, version
Ã,  if (keycode==1)Ã,  Ã, Debug(2,0);Ã,  // Ctrl-A, show walkable areas
Ã,  if (keycode==24)Ã,  Debug(3,0);Ã,  // Ctrl-X, teleport to room
}

There used to be something that said if b==1 keycode=0, but removed it and its still flashing in room 1. I cant understand why. Maybe you know.

Well, looking at the global script from a freshly started new game, that part of the code looks like:

function on_key_press(int keycode) {
Ã,  // called when a key is pressed. keycode holds the key's ASCII code
Ã,  if (IsGamePaused() == 1) keycode=0;Ã,  // game paused, so don't react to keypresses
Ã,  if (keycode==17)Ã,  QuitGame(1);Ã,  Ã, // Ctrl-Q
Ã,  if (keycode==363) SaveGameDialog();Ã,  Ã, // F5
Ã,  if (keycode==365) RestoreGameDialog();Ã,  // F7
Ã,  if (keycode==367) RestartGame();Ã,  // F9
Ã,  if (keycode==434) SaveScreenShot("scrnshot.bmp");Ã,  // F12
Ã,  if (keycode==9)Ã,  Ã, show_inventory_window();Ã,  // Tab, show inventory

Ã,  if (keycode==19)Ã,  Debug(0,0);Ã,  // Ctrl-S, give all inventory
Ã,  if (keycode==22)Ã,  Debug(1,0);Ã,  // Ctrl-V, version
Ã,  if (keycode==1)Ã,  Ã, Debug(2,0);Ã,  // Ctrl-A, show walkable areas
Ã,  if (keycode==24)Ã,  Debug(3,0);Ã,  // Ctrl-X, teleport to room
}


Ã,  Ã, So, maybe just use that, but instead of Ctrl-Q for quitting the game: if (keycode==17)Ã,  QuitGame(1);
...change it to: if (keycode==359) QuitGame(1);
Title: Re: Keycode Problem
Post by: Estaog on Thu 17/06/2004 15:15:57
Quote from: Barbarian on Thu 17/06/2004 13:53:22
Ã,  Ã, So, maybe just use that, but instead of Ctrl-Q for quitting the game: if (keycode==17)Ã,  QuitGame(1);
...change it to: if (keycode==359) QuitGame(1);

You mean change it to (keycode==359) GuiOn(1);
Right?
Title: Re: Keycode Problem
Post by: Scorpiorus on Thu 17/06/2004 15:38:33
Yes, put GuiOn(1) instead and see if it works.
Title: Re: Keycode Problem
Post by: Estaog on Fri 18/06/2004 12:54:09
Nope it still flashes!
Title: Re: Keycode Problem
Post by: Scorpiorus on Fri 18/06/2004 14:11:56
What do you mean by 'flashes', does the GUI come up and then quickly disappear?
Title: Re: Keycode Problem
Post by: Radiant on Fri 18/06/2004 14:25:24
Maybe your GUI is being turned off somewhere else?
Are you doing this:


if (IsGUIOn (1) == 0) {
  if (keycode == 42) GUIOn (1);
}

if (IsGUIOn (1) == 1) {
  if (keycode == 42) GUIOff (1);
}


See what I mean? It may be the case that the same key turns the GUI back off?
Title: Re: Keycode Problem
Post by: Estaog on Fri 18/06/2004 15:44:15
Quote from: Scorpiorus on Fri 18/06/2004 14:11:56
What do you mean by 'flashes', does the GUI come up and then quickly disappear?

Yes thats what it does.

But then how come it onlyh flashes in that room?
Title: Re: Keycode Problem
Post by: SSH on Fri 18/06/2004 15:54:26
Check that room script... you probably have a GUIOFF in your repeatedly execute when you meant for it to be in the before fadein interaction...
Title: Re: Keycode Problem
Post by: Estaog on Fri 18/06/2004 16:15:42
PlayMusic (1);
GUIOff (1); 
GUIOff (0); <= (:o)
if (cut==3) {
  ObjectOn (0);
  ObjectOn (1);

Why watever do you mean?  ::)
;)