Hey, I'm trying to use these two functions:
///////////////////////////////////////////////////////////////////////////////
function btnSaveGame_OnClick(GUIControl *control, MouseButton button)
{
txtNewSaveName.Text = nick;
int gameSlotToSaveInto = lstSaveGamesList.ItemCount + 1;
int i = 0;
while (i < lstSaveGamesList.ItemCount)
{
if (lstSaveGamesList.Items[i] == txtNewSaveName.Text)
{
gameSlotToSaveInto = lstSaveGamesList.SaveGameSlots[i];
}
i++;
}
SaveGameSlot(gameSlotToSaveInto, txtNewSaveName.Text);
close_save_game_dialog();
}
function btnIconSave1_OnClick(GUIControl *control, MouseButton button)
{
int gameSlotToSaveInto = lstSaveGamesList.ItemCount + 1;
gSaveGame.Visible = true;
// Get the list of save games
lstSaveGamesList.FillSaveGameList();
if (lstSaveGamesList.ItemCount > 0)
{
//If there is at least one, set the default text
//to be the first game's name
txtNewSaveName.Text = lstSaveGamesList.Items[0];
}
else
{
txtNewSaveName.Text = "";
}
mouse.UseModeGraphic(eModePointer);
gIconbar.Visible = false;
}
/*//////////////////////////////////////////////////////////////////////////
With this function:
function btnQuit_OnClick(GUIControl *control, MouseButton button)
{
btnIconSave1_OnClick(btnIconSave1, eMouseLeft);
Wait(20);
btnSaveGame_OnClick(btnSaveGame, eMouseLeft);
QuitGame(1);
}
All seems to work, however I have to press the quit button twice for the save function to work.
Anyone have any idea why I'm getting this type of behavior from this?
You can't code like this. You have to understand what a command does before you use it.
Calling those two functions one after another, the only lines from btnIconSave1_OnClick that have any effect are:
lstSaveGamesList.FillSaveGameList();
mouse.UseModeGraphic(eModePointer);
gIconbar.Visible = false;
And the latter two don't even really do anything save game related.
Removing the rest wouldn't make any difference.
What the original code does is check whether the entered save game name is the same as that of an existing save game. If it is, that save game is overwritten; to avoid having two save games with the same name (because they can't be distinguished in a list that only shows the name).
Since you're setting the name to nick, you're overwriting the same save game every time.
I have no idea why you think you have to press the button twice, but that's clearly not what's wrong with your code.
What exactly do you intend to do?
Do you want save game names called "nick1", "nick2", etc. where nick is the player's nickname?
Yes, The code currently saves nick1 nick2 nick3 etc from a predefined string.
Before the game starts the player is asked their name which is inputted into the:
String nick;
Everything works great except if i click quit, when those 2 commands fire off it doesn't immediately save, I have to click play instead of quit, then press quit again and it saves correctly.
Well since this is the case, Anyone know if theres a way i can just cause this function to run twice automatically?
Whoops >< just saw no bumping in the forum rules :o
AHAHAH I finally figured it out!
its because you cant run both of the functions twice in the same GUI.
[SOLVED]