Author Topic: Help with GUI text list control  (Read 1323 times)

I just started learning about making GUIs, so I really don't have alot of experience with this.

I have a text list that works fine, and I want a function that can test which line is selected. I thought the code for this was List.getSelectedID(); , but that always defaults to line 0, no matter which line is selected.

Can someone help me out?

Code from client.cs
Code: [Select]
function PerkGui::HelpBuySelected(%gui)
{
%line = PerkGui_PerkList.getSelectedID();
%item = getField(PerkGui_PerkList.getRowTextById(%line), 0);
PerkDescription.SetText("This would purchase the item on line " @ %line @ "\n\nThis item is " @ %item);
}

Code from the GUI
Code: [Select]
new GuiScrollCtrl() {
         profile = "GuiScrollProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "10 50";
         extent = "300 400";
         minExtent = "8 2";
         visible = "1";
         willFirstRespond = "0";
         hScrollBar = "alwaysOff";
         vScrollBar = "dynamic";
         constantThumbHeight = "0";
         childMargin = "0 0";
         rowHeight = "40";
         columnWidth = "30";

         new GuiTextListCtrl(PerkGui_PerkList) {
            profile = "GuiTextListProfile";
            horizSizing = "right";
            vertSizing = "bottom";
            position = "1 1";
            extent = "298 2";
            minExtent = "8 2";
            visible = "1";
            command = "PerkGui.Perklist();";
            enumerate = "0";
            resizeCell = "1";
            columns = "0 70 130 220";
            fitParentWidth = "1";
            clipColumnText = "0";
         };
      };

Try this:
Code: [Select]
function PerkGui::HelpBuySelected(%gui)
{
%line = PerkGui_PerkList.getRowTextById(PerkGui_PerkList.getSelectedId());
%item = getField(%line, 0);
PerkDescription.SetText("This would purchase the item on line " @ %line @ "\n\nThis item is " @ %item);
}

I tried that, but it's not exactly what I'm looking for and it still goes to the first line every time.



Right now, the list itself isn't programmed yet, because I just want to get the buying function to work.


I found a solution. As it turns out, there is a default command called onSelect that works for things like this. I'm still not sure why getSelectedId() didn't work, but this works great!
Code: [Select]
function PerkGui::onSelect(%line, %name, %cost, %section, %status)
{
   //stuff to do
}

revalation:
getSelectedID() gets two things. first is the id of the list, which is some random number, then it gets the info for the line you picked! if you did something like
Code: [Select]
getWord(getSelectedId(%var), 1); it might work, but i'm happy with the other one.