Blockland Forums > Modification Help
Help with GUI text list control
Nexus:
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: ---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);
}
--- End code ---
Code from the GUI
--- Code: ---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";
};
};
--- End code ---
Red_Guy:
Try this:
--- Code: ---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);
}
--- End code ---
Nexus:
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.
Nexus:
Nexus:
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: ---function PerkGui::onSelect(%line, %name, %cost, %section, %status)
{
//stuff to do
}
--- End code ---