- Home /
Inventory Script Trouble
( this is done in C#) Alright, so basically I loot items, it transfers over to my dictionary on my inventory script, from there It goes into a GUI button where I can click it and it will do its effect. (first three buttons are drinks, next three is food, so on) well the problem is I can keep using a item even though its a empty string in that dictionary slot. So I loot the can of soda, I get thirsty, I use it and it makes my thirst return to full, button goes blank signifying its empty, However i click again and it works again.
Heres a sample of what I have currently in this section (at about line 200 or so)
GUILayout.BeginHorizontal();
// Here I tried doing a If(InventoryNameDictionary[0] != Itemobject.SodaItem.Name){
if(GUILayout.Button(InventoryNameDictionary[0], GUILayout.Height(50))){
InventoryNameDictionary[0] = string.Empty;
curthirst = maxthirst;
}
}
//however it did nothing
if(GUILayout.Button (InventoryNameDictionary[1], GUILayout.Height(50))){
InventoryNameDictionary[1] = string.Empty;
curthirst = maxthirst;
}
if(GUILayout.Button (InventoryNameDictionary[2], GUILayout.Height(50))){
InventoryNameDictionary[2] = string.Empty;
curthirst = maxthirst;
}
Any Help is appreciated Thanks!
Answer by KMKxJOEY1 · Apr 19, 2014 at 05:27 PM
Although you are setting the string to empty, you need to disable the button's effect is the string is empty like so:
if(GUILayout.Button(InventoryNameDictionary[0], GUILayout.Height(50)) && InventoryNameDictionary[0] != string.Empty){
InventoryNameDictionary[0] = string.Empty;
curthirst = maxthirst;
}