Custom load menu with listbox (SOLVED)

Started by deftonesrule, Thu 18/05/2006 06:55:35

Previous topic - Next topic

deftonesrule

hello

i made a room with a nifty bg and i made a custom gui and it has :

listbox
slider
load button
cancel button

as of right now I'm still a total scripting nub.

from reading the manual i managed to get this far with the list box :
_________________________________________
#sectionstart savedgameslist_SelectionChange  // DO NOT EDIT OR REMOVE THIS LINE
// Restore menu listbox code
function savedgameslist_SelectionChange(GUIControl *control) {
  ListBox.AddItem(0);
  ListBox.AddItem(1);
  ListBox.AddItem(2);
  ListBox.AddItem(3);
  ListBox.AddItem(4);
 
  ListBox.AddItem(0);
  ListBox.AddItem(1);
  ListBox.AddItem(2);
  ListBox.AddItem(3);
  ListBox.AddItem(4);

}
___________________________________
i assumed that i would need to put 0-4 in it to called games saves but then again i think i need to put another thing in there so it knows to display a game save first the have a numberial variable.

then after further reading i attepted to try :
_________________________________________________
#sectionstart savedgameslist_SelectionChange  // DO NOT EDIT OR REMOVE THIS LINE
// Restore menu listbox code
function savedgameslist_SelectionChange(GUIControl *control) {
  ListBox.FillSaveGameList()
  lstSaveGames.SelectedIndex;
 
}
_____________________________________
assuming this fetches the list on its own.

both gives me the error :
Error (line 171): must have an instance of the struct to access a non-static member

function savedgameslist_SelectionChange(GUIControl *control) {  - is line 170 -


i know I'm doing something wrong and its something as simple as my syntax. i dont know if there is a tutorial on the subject of making your own load menu so I'm hoping for a little help on this one. I'm not worried about the other things yet.

any help would be greatly appreciated

Ashen

You need to replace the ListBox part (of FillSaveGameList, AddItem, etc) with the name of your ListBox (so AGS knows which ListBox to fill, add to, whatever), e.g.:

lstSaveGames.FillSaveGameList();

Also, you'll need to do that when you open the Load GUI, and not when you change the selected item (as you have it now). Finally, the lstSaveGames.SelectedIndex; line doesn't actually do anything here - you need to tell it what to do with the index, e.g.:

RestoreGameSlot(savegameindex[lstSaveGames.SelectedIndex]);
I know what you're thinking ... Don't think that.

deftonesrule

Okay so heres where i am so far with the list box :

I renamed the list box to : MyListBox
I assumed the name of the listbox in your example was: lstSaveGames

so heres my code so far :
____________________________________________
#sectionstart savedgameslist_SelectionChange  // DO NOT EDIT OR REMOVE THIS LINE
// Restore menu listbox code
function savedgameslist_SelectionChange(GUIControl *control) {
  MyListBox.FillSaveGameList();
  RestoreGameSlot(savegameindex[MyListBox.SelectedIndex]);
 
  }
______________________________________________

with this i get no error when saving my game and code however ... it dosent  display a list of saved games.

i know for a fact that i have 3 saved games called...

deftones1
deftones2
deftones3

=o/

Ashen

Quote from: Ashen on Thu 18/05/2006 11:09:47
Also, you'll need to do that when you open the Load GUI, and not when you change the selected item (as you have it now)

It looks like you're still calling FillSaveGameList on selection change. Move that line to wherever you turn the Load GUI on (e.g. on_key_press, another GUI button, etc).
I know what you're thinking ... Don't think that.

deftonesrule

your still going a little over my head ashen but heres what im up to now:

i was originaly putting script into the global script editer lke a dumbass.

i went to my interactions and did this :

after playe enters room after fade in,

game show gui 4
run script

then i double clicked on runscript and added the code there !

  // script for Room: Player enters room (after fadein)
  // running the listbox script to display saved games

MyListBox.FillSaveGameList(); 


so now my list box is working perfectly..

now for the actual load button....

ive named the load button "loadsubmit"..

so how should i code this ?  with :

RestoreGameSlot(savegameindex[MyListBox.SelectedIndex]);        ?????

i know i need to somehow call "loadsubmit" before this line runs at all. this way the highlighted save loads when the load button itself is pressed.. ., arggg

Ashen

You've named the button, OK. Now double-click it in the editor (make sure the script editor is CLOSED first). You should get a popup box asking you to name the script, just click OK and you'll be taken into the global script at a point that looks someting like:
Code: ags

#sectionstart loadsubmit_Click // DO NOT EDIT OR REMOVE THIS LINE
function loadsubmit_Click(GUIControl *control, MouseButton button) {

  }
#sectionstart loadsubmit_Click // DO NOT EDIT OR REMOVE THIS LINE


This is the Control function for the loadsubmit button - anything you put into that function will be run when you press the button. (This is the basic procedure for creating any GUI Controls that can be interacted with - Buttons, TextBoxes, ListBoxes, etc.) In this case, you know what to put in there, but you sould also add a check that something is selected, e.g.:

Code: ags

#sectionstart loadsubmit_Click // DO NOT EDIT OR REMOVE THIS LINE
function loadsubmit_Click(GUIControl *control, MouseButton button) {
  if (MyListBox.SelectedIndex == -1) Display ("Select a game to load.");
  else RestoreGameSlot(savegameindex[MyListBox.SelectedIndex]);
  }
#sectionstart loadsubmit_Click // DO NOT EDIT OR REMOVE THIS LINE


This thread and this thread deal with save/load GUIs in more detail, and may be some help. (As does this one, but it's in old, pre-V2.7 code and might not be much use to you).
I know what you're thinking ... Don't think that.

deftonesrule

perfect ashan! it works great. still have the other buttons to do but ill get to those later. thanks!

SMF spam blocked by CleanTalk