I want top make a options menu with different settings by sliders. Some are the volume of sound and music.
By a slider i change/make a value, this value should will receive by a button (by click on it):
SetMusicMasterVolume(GetSliderValue(4, 1));
But i doesn't run. I can hear music but very soft, equal which value is set up by the slider. GUI 4 is the options menu (pop up) and 1 is the slider for music.
What do i wrong
Another question: is this value saved in save game sor must i change i every time i play the game? Could it be saved in sve games?
Are you sure that button is set to "run script' ?
Put a Display function alongside with that set volume line to see if that part of the code is indeed executed.
eg.
Display("Blah!");
SetMusicMasterVolume(GetSliderValue(4, 1));
No, it's all correct. I installed the displaymessage and it was shown in the game, but music is still broken.
I also try to create own load and save menus and i have the same problems. All buttons, labels etc. working correct, the save menu saves games, but in the list box they are not listed and i also can't load any saves games. Why? Whats wrong?
// extra load menu
if (interface == 3) {
int index;
if (button == 1) {
index=ListBoxGetSelected(3,0);
RestoreGameSlot(savegameindex[index]);
}
if (button == 2) {
GUIOff(3);
GUIOn(0);
}
}
// extra save menu
if (interface == 4) {
string text;
int index;
if (button == 1) {
GUIOn(0);
GUIOff(4);
} // ende button 1
if (button == 0) {
index=ListBoxGetNumItems(4,3);
if (index<10) { // only 10 save slots are available!
GetTextBoxText(4,2,text);
GUIOff(4);
GUIOn(0);
SaveGameSlot(index+1,text);
} // ende index
else {
index=ListBoxGetSelected(4,3);
GetTextBoxText(4,2,text);
GUIOff(4);
GUIOn(0);
SaveGameSlot(savegameindex[index],text);
} // ende else
} // ende button 0
}
Again: labels, boxes, buttons are correct setted up and AGS don't show any error messages or something, so i don't know where's the problem. I need every help!
You may try posting the whole GUI script here, so we may see about that volume thingie.
For the load menu to work, you have to call ListBoxSaveGameList(3,0); (seeing from your code that the load GUI is #4, and the list box is button #0, see manual for more detail) whenever you bring up the GUI (for example, if the Load GUI pops up when you click a button, you have to put that line in the code for that particular button. That's because list boxes are never updated automatically, you have to do it yourself when needed. Did you do that?
Here is my global script.
I have following Bugs:
1) Savegames with same name will not overwritten
2) Volume of music & sound cannot changed by the sliders
3) Save volume values in save games (i never could test it, will it saved in save games???)
4) music on/off function is missing (i don't know, how I must coding; by "StopMusic" the game crashes)
#sectionstart unhandled_event // DO NOT EDIT OR REMOVE THIS LINE
function unhandled_event (int what, int type) {
}
#sectionend unhandled_event // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart game_start // DO NOT EDIT OR REMOVE THIS LINE
function game_start() // called when the game starts, before the first room is loaded
{
SetGlobalInt(299,8);
game.items_per_line=4;
game.num_inv_displayed=4;
game.text_speed=7;
}
#sectionend game_start // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart repeatedly_execute // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
string buffer, text;
int cur_mode, mode;
mode = GetGlobalInt(299);
cur_mode = GetCursorMode();
StrCopy (text, "");
// Je nach Cursor-Modus wird jetzt ein Verb in die Statuszeile geschrieben
if (cur_mode == MODE_WALK) StrCat(text,"Gehe zu ");
if (cur_mode == MODE_LOOK) StrCat (text,"Schau an ");
if (cur_mode == 2) StrCat (text,"Benutze ");
if (cur_mode == 3) StrCat(text,"Rede mit ");
if (cur_mode == 5) StrCat(text,"Nimm ");
if (mode == 7) {
StrCat(text, "Benutze ");
GetInvName (player.activeinv, buffer);
StrCat(text, buffer);
StrCat(text, " mit ");
}
// Das Objekt unter dem Cursor finden und an die Statuszeile anhängen
GetLocationName(mouse.x, mouse.y, buffer);
StrCat(text, buffer);
SetLabelText (0, 2, text);
}
#sectionend repeatedly_execute // DO NOT EDIT OR REMOVE THIS LINE
function show_inventory_window()
// This demonstrates both types of inventory window - the first part is how to
// show the built-in inventory window, the second part uses the custom one.
// Un-comment one section or the other below.
{
// ** DEFAULT INVENTORY WINDOW
InventoryScreen();
/*
// ** CUSTOM INVENTORY WINDOW
GUIOn (INVENTORY);
// switch to the Use cursor (to select items with)
SetCursorMode (MODE_USE);
// But, override the appearance to look like the arrow
SetMouseCursor (6);
*/
}
#sectionstart on_key_press // DO NOT EDIT OR REMOVE THIS LINE
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==367) RestartGame(); // F9
if (keycode==434) SaveScreenShot("scrnshot.pcx"); // F12
if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
if (keycode==22) Debug(1,0); // Ctrl-V, version
}
#sectionend on_key_press // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart on_mouse_click // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(int button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
if (IsGamePaused()==1) // Game is paused, so do nothing (ie. don't allow mouse click)
{
}
else if (button==LEFT)
{
ProcessClick(mouse.x,mouse.y,GetCursorMode());
SetCursorMode(MODE_WALK);
}
else if (button==RIGHT)
{
if (GetLocationType(mouse.x, mouse.y) == 2) {
SetGlobalInt(299,9);
ProcessClick(mouse.x, mouse.y, MODE_WALK);
SetGlobalInt(299,0);
}
else {
FaceLocation(GetPlayerCharacter(), mouse.x, mouse.y);
ProcessClick(mouse.x, mouse.y, MODE_WALK);
SetCursorMode(MODE_LOOK);
}
}
}
#sectionend on_mouse_click // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart interface_click // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button) {
// Main menu (commandos and inventory)
if (interface == 0) {
if (button == 1) { // Pick up
SetCursorMode(5);
SetGlobalInt(80,3);
}
if (button == 3) { // Talk
SetCursorMode(3);
SetGlobalInt(1,1);
SetGlobalInt(80,7);
}
if (button == 4) { // Use
SetCursorMode(2);
SetGlobalInt(80,1);
}
if (button == 5) { // Look
SetCursorMode(1);
SetGlobalInt(80,4);
}
if (button == 6) { // Options
SetGlobalInt(80,6);
GUIOn(2);
GUIOff(0);
}
if (button == 7) { // Quit Game
SetGlobalInt(80,9);
GUIOn(5);
GUIOff(0);
}
if (button == 8) { // Load
SetGlobalInt(80,5);
ListBoxSaveGameList(3,0);
GUIOff(0);
GUIOn(3);
}
if (button == 9) { // Save
SetGlobalInt(80,9);
ListBoxSaveGameList(4,3);
GUIOn(4);
GUIOff(0);
}
if ((button == 11) & (game.top_inv_item < game.num_inv_items - 4))
game.top_inv_item = game.top_inv_item + 1;
if ((button == 10) & (game.top_inv_item > 0))
game.top_inv_item = game.top_inv_item - 1;
}
// Options menu
if (interface == 2) {
if (button == 0) {
GUIOff(2);
GUIOn(0);
}
if (button == 6) {
SetSoundVolume(GetSliderValue(2,2));
PlaySound(1);
}
if (button == 5) {
DisplayMessage(999);
SetMusicMasterVolume(GetSliderValue(2,1));
PlayMusic(1);
}
}
// Load menu
if (interface == 3) {
int index;
if (button == 1) {
index=ListBoxGetSelected(3,0);
RestoreGameSlot(savegameindex[index]);
}
if (button == 2) {
GUIOff(3);
GUIOn(0);
}
}
// Save menu
if (interface == 4) {
string text;
int index;
if (button == 1) {
GUIOn(0);
GUIOff(4);
}
if (button == 0) {
index=ListBoxGetNumItems(4,3);
if (index<10) {
GetTextBoxText(4,2,text);
GUIOff(4);
GUIOn(0);
SaveGameSlot(index+1,text);
} else {
index=ListBoxGetSelected(4,3);
GetTextBoxText(4,2,text);
GUIOff(4);
GUIOn(0);
SaveGameSlot(savegameindex[index],text);
}
}
}
// Quit game
if (interface == 5) {
if (button == 0) {
QuitGame(0);
}
if (button == 1) {
GUIOn(0);
GUIOff(5);
}
}
}
#sectionend interface_click // DO NOT EDIT OR REMOVE THIS LINE
Can nobody help me??? I need help. :(
1. That's because your code probably save it into a new slot, to overwrite savegame with same name, you probably need to script on codes that check if the text in the textbox matches one of the listbox entries, then retrieve the slot # and save it as that slot.
2. I didn't read the code thoroughly, and I'm not sure about the problem. Maybe some other people can help you.
3. Should be
4. What's teh crash message you're getting?
By the way, was that load game problem fixed yet?
If there're still problems you can also update the game files for us to check.
If stopmusic() crashes, you could turn music off by setting its volume to zero.
Now i can load and save games. No problem.
Ok No. 4 is changed, thx for the clue.
But where can I get such a script, which tests the name of existing save games and I also have the problem, that the slider values are not run….
Anybody an idea of solution for my problem? Mh? I try and try, but it will not run...
As for the slider volume problem, are the min and max values set properly? Music values can go from 0 - 100, so you should set the slider min and max accordingly.
For instance, here's what I have for mine.
Ã, Ã, if (button == 5) {// Music Slider
Ã, Ã, Ã, musicvolume = (GetSliderValue (SYSTEM, 5));
Ã, Ã, Ã, SetMusicMasterVolume (musicvolume);
Ã, Ã, Ã, string buffer;
Ã, Ã, Ã, StrFormat (buffer, "%d", musicvolume); // This just puts the music volume value in a string
Ã, Ã, Ã, SetLabelText (SYSTEM, 14, buffer); // This prints the volume value string to a label above my Volume slider
Ã, Ã, }
The Slider's min is 0 and the max is 100. Though, I admit, I should probably store volume in a GlobalInt as I am 70% sure they are saved when the player saves the game.
Mmh, i get an error like "token" problem at line:
musicvolume = (GetSliderValue (SYSTEM, 5));
AGS said musicvolume is the problem... what's wrong??
Did you declare the variable musicvolume first?
Put int musicvolume; on top of the script.
Yeah, you'll want int musicvolume; as I didn't declare it in the snippet I pasted as it was declared above.
Also, you might want this snippet too.
else if (button == 7) { // System Window
// Set slider and label values for speed, music, and sound
string buffer;
StrFormat (buffer, "%d", GetGameSpeed ());
SetLabelText (SYSTEM, 13, buffer);
SetSliderValue (SYSTEM, 8, GetGameSpeed ());
StrFormat (buffer, "%d", musicvolume);
SetLabelText (SYSTEM, 14, buffer);
SetSliderValue (SYSTEM, 5, musicvolume);
StrFormat (buffer, "%d", soundvolume);
SetLabelText (SYSTEM, 15, buffer);
SetSliderValue (SYSTEM, 10, soundvolume);
GUIOn (SYSTEM);
SetMouseCursor (6);
}
That example is for the Icon Bar so that it set the values of the sliders and the numeric label to the previously set values. Otherwise, it'll just load the GUI with whatever you set the default values to be.