As most things when it comes to programming this turned out to be surprisingly simple. First I create a window with the exact number of buttons as items my inventory is going to contain in the whole game. Each of this buttons must have the same name as the items.
Then, when I call the window, I organize each button according to the order in which the items appear in the inventory:
var xpos=15;
for(var i=0; i<Game.NumItems; i=i+1)
{
var nombre = Game.GetItem(i);
var prov = Invenbut.GetControl(nombre.Name);
prov.SkipTo(xpos,prov.Y);
xpos=xpos+65;
}
I still have to make sure I hide the buttons that are not yet in the inventory and show the ones that are. I'm a bit stuck there because the only thing I can think of is creating an array with all the buttons names, creating a second array with all the inventory items names, substract the second array from the first array and make the resulting buttons visible. It's a bit of a headache so if anyone can think of a more efficient way to do it please let me know.