It might also be easier if you assign a variable to the object containing the number of the control.
For example:
PHP Code:
new GuiBitmapButtonCtrl( "InventoryButton" @ i) {
x = 16 + (32 + 8)*i, y = 16;
width = 32, height = 32;
mouseoverbitmap = tokens[1];
normalbitmap = tokens[1];
pressedbitmap = tokens[1];
// ** Added
this.buttonnumber = i;
thiso.catchevent(this, "onAction", "onButtonPressed");
}
// ** Modified
function onButtonPressed(obj) {
player.chat = "Button Number: " @ obj.buttonnumber @ " pressed!";
}