- Home /
Help with Lists and SelectionGrid
Hello, I have two questions to ask about the Lists because I am making an inventory. 1) I use GUILayout.SelectionGrid, who show a string List. In these List there are my items, like Axe or Sword. So in my list I have "Axe" and "Sword" and the selectionGrid show it very well. But, I also want to translate my game, so Axe and Sword will change if the game is in Italian or French per example. The problem is I can't directly do it in the list because the string will change, it is possible to, if in the list the item is "Axe", in the inventory grid it would be item.axe (per example)?
2) I also want to add the number of an item, it would be perfect if I can do like that: item.axe + "(" + axeNumber.ToString() + ")".
Cordialy.
My code:
public List<string> InventoryItemName = new List<string>();
in OnGUI ():
customerGridNames = new string[InventoryItemName.Count];
for(int cnt = 0; cnt < InventoryItemName.Count; cnt++) {
customerGridNames[cnt] = InventoryItemName[cnt];
}
scrollPos = GUILayout.BeginScrollView (scrollPos);
selectedGrid = GUILayout.SelectionGrid(selectedGrid, customerGridNames, 1);
if (selectedGrid == item.axeID) mainID = item.axeID;
if (selectedGrid == item.swordID) mainID = item.swordID;
GUILayout.EndScrollView ();
Answer by MrAkroMenToS · Jul 13, 2014 at 10:23 AM
I recommend you to store an ID for each item in the list instead of store their names, because the name is not the identifier but a property. Make a mini database (an array an other list a txt file) to store an item's properties.
For example:
0;Axe;30;0;5
It means:
Id - 0
Name - Axe
Attack damage - 30
Magic damage - 0
Attack speed - 5
Store only the ID, here the "0" in the grid and if you want to rename the thing you can do it easily.
For your second question, I recommend you to make a list to store the "currentItems". It can be something like that: 0;3;1 -- the item with ID 0 count of 3 on the 1th pleace... Figure it out.
I hope it helped let me know if you have any more problems!
In the Item.cs, I have all my item, per example for the Axe it's: axeID = 1; item_axe = "Axe"; axeIDnumber = x (number of axe in the inventory); So your way seem too hard for me :/ (I'm not very good :p). It's not possible to, if in the SelectionGrid if the selected ID is 1, the name of the Button is "Axe ("+number+")"?
EDIT: ok I understand (after 30 $$anonymous$$utes...). I will try to do two list, one whith the ID and another with the name who will can change.
Please send me a picture where i can see the in-game inverntory, and a we lines where i can see the item.cs class's code. And please edit the image so i can see what do you want to do exactly!
----------------------------------------------------------- After i saw your EDIT--- EDIT: here is an example:
List<string[]> items = new List<string[]>();
items.Add(new string[]{"0", "Axe", "30", "0", "5"});
items.Add(new string[]{"0", "Sword", "20", "0", "10"});
the items[0] will be the axes propery the items[1] is the sword You can get the ID of the axe : items[0][0] You can get the attack speed of the sword: items[1][4]
Ok so it's not really working... The name and the ID are not the seem, it's totally bugged :/ I will retry another day for this, whith the string list and etc...
Your answer
Follow this Question
Related Questions
Method is called, but GUI doesn't show up 1 Answer
A node in a childnode? 1 Answer
Scroll List Problem 1 Answer
[SOLVED] First array slot blocking second array slot 1 Answer
C# ArrayList match to string? 1 Answer