Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Construed on Wed 15/02/2012 16:18:40

Title: Predefined string[SOLVED]
Post by: Construed on Wed 15/02/2012 16:18:40
Hi,
I have a predefined string "nick" which the player enters into a text box.
I would like for the game to use this "nick" as the save game name.
I would like it to use that string no matter if the save game list has 0 index or not.
This is the code I'm playing with.

function btnIconSave_OnClick(GUIControl *control, MouseButton button)
{
 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
 {
   // No save games yet, default empty text.
   txtNewSaveName.Text = "";
 }
 mouse.UseModeGraphic(eModePointer);
 gIconbar.Visible = false;
}


And this is what I'm trying to do with it, not seeming to work though.


function btnIconSave_OnClick(GUIControl *control, MouseButton button)
{
 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
 {
   // was trying to change this to
   txtNewSaveName.Text = nick;
   //but it appeared to have no effect
   //also this only effects it if the index is 0 i would like it to use the nick string
   //in any case
 }
 mouse.UseModeGraphic(eModePointer);
 gIconbar.Visible = false;
}
Title: Re: Predefined string
Post by: monkey0506 on Thu 16/02/2012 00:57:37
Wow. I was trying to answer this earlier this morning (while at work! :P), and I'm surprised no responses yet.

Grim: Do you understand what the following line means?

if (lstSaveGamesList.ItemCount > 0)

I don't mean to sound rude, but your question seems to be a fairly straightforward answer, unless I'm misunderstanding you:

Quotei would like it to use the nick string in any case

So based on that:

function btnIconSave_OnClick(GUIControl *control, MouseButton button)
{
  gSaveGame.Visible = true;
  // Get the list of save games
  lstSaveGamesList.FillSaveGameList();
  // removed the if-else block entirely
  txtNewSaveName.Text = nick;
  mouse.UseModeGraphic(eModePointer);
  gIconbar.Visible = false;
}


Of course you didn't post code showing where the String variable nick is created and set, but I'll give the benefit of a doubt that you did that appropriately. ;)

If this still doesn't work, please let us know exactly what behavior you do see, not just that it's not working.
Title: Re: Predefined string
Post by: Construed on Thu 16/02/2012 01:14:48
Thanks for answering bud.
This is what i got going on.

String nick;

///Which is then changed by this a short while later in the code:

function bconnect_Click(GUIControl *control, MouseButton button) {
nick = "stranger";
nick = Game.InputBox("Enter a nick name (A-Za-z0-9_):");
Connect(nick);

//I would guess if (lstSaveGamesList.ItemCount > 0) means if savegameslist greater  than zero


But I'm totally exhausted after a long long day so I'll try your code tomorrow.
Don't take it as ungratfulness because I'm very greatful for your reply.
Get back to ya tomorrow and thanks again :D
Title: Re: Predefined string
Post by: Construed on Thu 16/02/2012 06:35:27
Well, i woke up in the middle of the night and couldnt sleep, gave it a whirl and...


---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x00427CC0 ; program pointer is +6, ACI version 3.21.1115, gtags (6,15)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and post the details on the AGS Technical Forum.

in "GlobalScript.asc", line 1429


Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.

An error file CrashInfo.dmp has been created. You may be asked to upload this file when reporting this problem on the AGS Forums. (code 0)
---------------------------
OK  
---------------------------

Perhaps it has to do with this referring function?


function btnSaveGame_OnClick(GUIControl *control, MouseButton button)
{
 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();
}

But perhaps not, i tried commenting out relying variables with no avail...
Title: Re: Predefined string
Post by: Construed on Thu 16/02/2012 21:08:38
[edit]
Solved