Hello,
I am trying to build a GUI that holds a variables in a Listbox, ideally looking something like this:
Milk 4 pints
Chocolate Milk 0 pints
Orange 2 pints
Jersey Milk 1 pints
These variables would change depending on whether the player takes the items or not.
I have tried to build the list using Additem as follows:
Listbox1.Additem ("Milk %d pints", Milkamount);
I am being told that "wrong number of parameters in call to Listbox1.Additem" and have no idea what this means!
I have read the manual attached to the software, read all the tutorials I can find and watched all of Densming's excellent videos on youtube, but I cannot seem to find a way around this problem. I can see on the forums that people have asked a similar question and seem to have solved their own problems, but frankly I don't understand the solutions they have been given and I felt it would make more sense to explain my specific problem.
Any help would be greatly appreciated - I am something of a novice at scripting, but think I can grasp most things that make sense!
ListBox.AddItem can take only 1 parameter, which is a string.
To deal with situations like this you are combining 2 function calls: a creation of formatted string, and assignment of that final string:
String s = String.Format("Milk %d pints", Milkamount);
Listbox1.Additem(s);
or shorter
Listbox1.Additem( String.Format("Milk %d pints", Milkamount) );
As an additional tip, functions that support string formatting directly always end with "..." as the last parameter:
AbortGame(const string, ...)
Display(const string, ...)
String.Format(const string, ...)
There may be others (don't recall ATM) but these are common examples. If the last parameter isn't "..." then you can just call String.Format in place of the string parameter you want to format. ;)
Excellent! Works like a charm!
Thank you both.