Predefined string[SOLVED]

Started by Construed, Wed 15/02/2012 16:18:40

Previous topic - Next topic

Construed

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.
Code: ags

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.

Code: ags

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;
}
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

monkey0506

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?

Code: ags
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:

Code: ags
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.

Construed

#2
Thanks for answering bud.
This is what i got going on.
Code: ags

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
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

#3
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?

Code: ags

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...
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

Construed

#4
[edit]
Solved
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

SMF spam blocked by CleanTalk