s/l gui "type a name before u save." ?

Started by YotamElal, Sun 20/03/2005 10:52:04

Previous topic - Next topic

YotamElal

I tried to add an if to my s/l script, so that if you don't type anyhting in then
it tells you that need to.
It didn't work so I tried with the letter a. and even though I type "a" in the text box it still displays else... what can I do.

Code: ags

if (strDescription=="a") Display("You need to type in a name before you save.");
		    //  save to a new slot (with a GUI temporarily disabled):
		else { GUIOff(GUISAVELOAD);
		Display("else");
		SetDefaultCursor();
		SaveGameSlot(totalSlots + 1, strDescription); }



here is the hole s/l code:
Code: ags

int sldTextbox      = 0;  //  saveload textbox GUI object number;
int sldListbox      = 1;  //  saveload listbox GUI object number;
int sldSaveButton   = 2;  //  saveload save   button GUI object number;
int sldLoadButton   = 3;  //  saveload load   button GUI object number;
int sldDeleteButton = 4;  //  saveload delete button GUI object number;
int sldCancelButton = 5;  //  saveload cancel button GUI object number;
// Functions:
function on_event_SaveLoadDialogGUI(int event, int data) {
  //  if there is click over a textbox:
  if ((event == GUI_MDOWN) && (data == GUISAVELOAD) && (GetGUIObjectAt(mouse.x ,mouse.y) == sldTextbox)) {
	ListBoxSetSelected(GUISAVELOAD, sldListbox, -1); }
}
function UpdateSaveLoadDialogGUI() {
    int selectedItem = ListBoxGetSelected(GUISAVELOAD, sldListbox); // store an old value (to restore it later):  
    ListBoxSaveGameList(GUISAVELOAD, sldListbox); // update the savegame list (seleted item is reset here ot 0!):
    int totalSlots = ListBoxGetNumItems(GUISAVELOAD, sldListbox); // get the number of slots (it's == number of the items in a listbox):
    if (totalSlots > SAVELOAD_SLOTS_MAX) Display("You have too many saved games."); //  if we have exceeded the limits display a warning message:
    ListBoxSetSelected(GUISAVELOAD, sldListbox, selectedItem); // restore an old value (stored in selectedItem);
    return totalSlots; // return the number of saved slots:
}
function OpenSaveLoadDialog() {
//  Opens the save/load dialog:
    CentreGUI(GUISAVELOAD);                          //  centre the save/load GUI;
    GUIOn(GUISAVELOAD);                              //  turn the related GUI on;
    UpdateSaveLoadDialogGUI();                       //  refresh GUI's content (show saved games);
    ListBoxSetSelected(GUISAVELOAD, sldListbox, -1); //  remove the highlight:
    SetTextBoxText(GUISAVELOAD, sldTextbox, "");     //  clear a textbox;
    Wait(1);                                         //  update the screen to show the GUI;
    SetMouseCursor(6);                               //  override cursor to look like an arrow;
}

function CloseSaveLoadDialog() {
//  Closes the save/load dialog:
    if (GetRoomProperty("UseInteract") != 10) SetDefaultCursor();         //  restore cursor appearence;
    GUIOff(GUISAVELOAD);        //  turn the related GUI off;
}

function interface_click_SaveLoadDialogGUI(int button) {
//  Processes clicks on a save/load dialog GUI.
//  Note: it must be called from within the interface_click function!
        string strDescription;//  allocate string to transfer slot description:
        GetTextBoxText(GUISAVELOAD, sldTextbox, strDescription);
        int selectedItem = ListBoxGetSelected(GUISAVELOAD, sldListbox);//  get selected item:
    if (button == 50){
        GUIOff(GUISAVELOAD);
	SetDefaultCursor();
	SaveGameSlot(savegameindex[selectedItem], strDescription); }
    else if (button == 51){
        DeleteSaveSlot(savegameindex[selectedItem]);    //  delete the slot:
        int totalSlots = UpdateSaveLoadDialogGUI(); } //  update the save/load GUI and get the number of items:
    else if (button == sldListbox) { // if click on a *listbox item*:
     //  Show currently selected saved slot's description in a textbox:
        string buffer;    //  give us a temp buffer to transfer string:        
        //int
	selectedItem = ListBoxGetSelected(GUISAVELOAD, button);//  get selected item:
        ListBoxGetItemText(GUISAVELOAD, button, selectedItem, buffer);//  copy saved game description into 'buffer':
        SetTextBoxText(GUISAVELOAD, sldTextbox, buffer); } //  and finally, fill the textbox with what is stored in 'buffer':
    else if ( (button == sldSaveButton) || (button == sldTextbox) ) { // if click on a *save button* or *enter key* is pressed:
    // Save a game to slot:
        int totalSlots = UpdateSaveLoadDialogGUI();//  get total the number of slots:
        //int 
	selectedItem = ListBoxGetSelected(GUISAVELOAD, sldListbox);//  get selected item:
        //string strDescription;//  allocate string to transfer slot description:
        GetTextBoxText(GUISAVELOAD, sldTextbox, strDescription);//  fill 'strDescription' with the message in a listbox:
        if ( ( selectedItem >= 0 ) && ( selectedItem < SAVELOAD_SLOTS_MAX ) ) {//  if it's not out of bounds...
            //  overwrite save game slot (with a GUI temporarily disabled):
            SetGUIClickable(GUISAVELOAD, 0);
            GUIOn(OVERWRITE);
		 }
        else if ( (selectedItem == -1) && (totalSlots < SAVELOAD_SLOTS_MAX) ) { //  if there is no slot selected...
		if (strDescription=="a") Display("You need to type in a name before you save.");
		    //  save to a new slot (with a GUI temporarily disabled):
		else { GUIOff(GUISAVELOAD);
		Display("else");
		SetDefaultCursor();
		SaveGameSlot(totalSlots + 1, strDescription); }
		}
        else { Display("There are too many game slots. Please, choose an already existing item to overwrite!");
        UpdateSaveLoadDialogGUI();//  update the save/load GUI
        ListBoxSetSelected(GUISAVELOAD, sldListbox, -1);//  remove the highlight:
        SetTextBoxText(GUISAVELOAD, sldTextbox, ""); }//  clear a textbox;
    }
    else if (button == sldLoadButton) {// if click on a *load button*:
    // Try to delete a saved slot:
        //int
	selectedItem = ListBoxGetSelected(GUISAVELOAD, sldListbox);    //  get selected item:
        if ( ( selectedItem >= 0 ) && ( selectedItem < SAVELOAD_SLOTS_MAX ) ) {//  if it's not out of bounds...
            RestoreGameSlot(savegameindex[selectedItem]); }//  restore game from the slot:
        else { Display("Please, choose an item to load!");
	UpdateSaveLoadDialogGUI(); }//  update the save/load GUI
    }
    else if (button == sldDeleteButton) {  // if click on a *delete button*:
        // Try to delete a saved slot:
        //int
	selectedItem = ListBoxGetSelected(GUISAVELOAD, sldListbox);       //  get selected item:
        if ( ( selectedItem >= 0 ) && ( selectedItem < SAVELOAD_SLOTS_MAX ) ) {//  if it's not out of bounds...
           SetGUIClickable(GUISAVELOAD, 0);
		GUIOn(DELETE);
            //DeleteSaveSlot(savegameindex[selectedItem]);    //  delete the slot:
            //int totalSlots = UpdateSaveLoadDialogGUI();//  update the save/load GUI and get the number of items:
            //  When we delete *the last* slot the highlight is
            //  removed, so we should get it back by highlighting
            //  a new last slot:
            //if (ListBoxGetSelected(GUISAVELOAD, sldListbox) == -1){
                //  highlight the last item if required:
               // ListBoxSetSelected(GUISAVELOAD, sldListbox, totalSlots - 1); }
        }
        else Display("Please, choose a saved slot to delete!");
    }
    else if (button == sldCancelButton) {  // if click on a *cancel button*:
           CloseSaveLoadDialog();} // close the save/load GUI;
}
//####################################################################################################################
function on_event(int event, int data) {
  // called when an event happens (see AGS manual for details)
    //  inform our save/load GUI of the event;
    on_event_SaveLoadDialogGUI(event, data);
}


Ashen

Well, the first thing I can see is this:
Code: ags

if (strDescription=="a") Display("You need to type in a name before you save.");


You can't, AFAIK, compare strings using '=='. (In fact, I thought it returned an error on saving.) Does it work if you try:
Code: ags

if (StrComp ("", strDescription) == 0) Display("You need to type in a name before you save.");
I know what you're thinking ... Don't think that.

YotamElal

THNX for the code.
IT SOLVED my prob...

SMF spam blocked by CleanTalk