Hi. First off, I apologize if this has been covered. But I've searched the forums to no end. All I want to do, is assign keys to play particular sounds. In the global script under the function on_key_press I have
if (keycode == 'A') PlaySound(1);
I am replacing the mouse modes that are set with the default, as I have no playable character anyway and am trying to turn my keyboard into a musical instrument. I've also tried
if (keycode == eKeyA) PlaySound(1);
What am I doing wrong?
function on_key_press(eKeyCode keycode) {
// The following is called before "if game is paused keycode=0", so
// it'll happen even when the game is paused.
if ((keycode == eKeyEscape) && gRestartYN.Visible) {
//Use ESC to cancel restart.
gRestartYN.Visible = false;
gIconbar.Visible = true;
// If the panel's not ON, then the player must have gotten here by tapping F9,
// therefore his cursor needs restoring. If the panel IS on, then it doesn't,
// because it's already a pointer. Get used to thinking like this!!
if (!gPanel.Visible) mouse.UseDefaultGraphic();
return;
}
if ((keycode == eKeyEscape) && gPanel.Visible) {
// Use ESC to turn the panel off.
gPanel.Visible = false;
mouse.UseDefaultGraphic();
gIconbar.Visible = true;
return;
}
if ((keycode == eKeyEscape) && (gSaveGame.Visible))
{
// Use ESC to close the save game dialog
close_save_game_dialog();
return;
}
if ((keycode == eKeyEscape) && (gRestoreGame.Visible))
{
// Use ESC to close the restore game dialog
close_restore_game_dialog();
return;
}
if (keycode == eKeyReturn) {
// ENTER, in this case merely confirms restart
if (gRestartYN.Visible) RestartGame();
}
if (IsGamePaused() || (IsInterfaceEnabled() == 0))
{
// If the game is paused with a modal GUI on the
// screen, or the player interface is disabled in
// a cut scene, ignore any keypresses.
return;
}
// FUNCTION KEYS AND SYSTEM SHORTCUTS
if (keycode == eKeyEscape) {
// ESC
gPanel.Visible = true;
gIconbar.Visible = false;
mouse.UseModeGraphic(eModePointer);
}
if (keycode == eKeyCtrlQ) QuitGame(1); // Ctrl-Q
if (keycode == eKeyF5) show_save_game_dialog(); // F5
if (keycode == eKeyF7) show_restore_game_dialog(); // F7
if (keycode == eKeyF9) {
// F9, asks the player to confirm restarting (so much better to always confirm first)
gRestartYN.Visible = true;
gIconbar.Visible = false;
mouse.UseModeGraphic(eModePointer);
}
if (keycode == eKeyF12) SaveScreenShot("scrnshot.bmp"); // F12
if (keycode == eKeyTab) show_inventory_window(); // Tab, show inventory
// GAME COMMAND SHORTCUTS
if (keycode == 'A') PlaySound(1);
if (keycode == 'L') mouse.Mode=eModeLookat; //Note that all we do here is set modes.
if (keycode == 'U') mouse.Mode=eModeInteract; //If you want something else to happen, such as GUI buttons highlighting,
if (keycode == 'T') mouse.Mode=eModeTalkto; //you'll need some more scripting done.
if (keycode == 'I') mouse.Mode=eModeUseinv; //But this will, as-is, give you some standard keyboard shortcuts your players will very much appreciate.
// For extra cursor modes, such as pick up, feel free to add as you will.
// Uncomment the line below if you use the "Pick Up" mode.
//if (keycode == 'P' || keycode == 'G') mouse.Mode=eModePickup;
// DEBUG FUNCTIONS
if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory
if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version
if (keycode == eKeyCtrlA) Debug(2,0); // Ctrl-A, show walkable areas
if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room
if (keycode == eKeyCtrlW && game.debug_mode)
player.PlaceOnWalkableArea(); //Ctrl-W, move to walkable area
}
Alright, there it is. But all it is is just the default script. The only modification I've made so far is changing the keycode 'A' to playing a sound. The sound is an mpg in my Sounds folder titled, sound1
Can you post your whole 'on_key_press' function for us to check?