So all I want to do is pass the numerical value of the Button above the one the player presses to an integer. (From within another Function as opposed to within function btnInv7_OnClick() )
I tried this:
GUIControl *control = GUIControl.GetAtScreenXY(gInventory.Controls[startblock].X + 10, gInventory.Controls[startblock].Y - 10);
int block = control.ID;
if(InvBlock[block].full)
return false; // block1 is full
But this just ends in Null pointers, I don't think GUIControl has an ID parameter. I tried several other things like using AsButton, and searching the Beginner Forums with no success.
Thanks,
Mite
First of all, you do not check a pointer returned by GetAtScreenXY:
GUIControl *control = GUIControl.GetAtScreenXY(gInventory.Controls[startblock].X + 10, gInventory.Controls[startblock].Y - 10);
if (control == null)
return false; // or otherwise cancel the action
It is essential to do this check when you are using GetAtScreenXY, just in case, to prevent null pointer errors.
2) Secondly, according to the manual, GUIControl.X "specifies its left edge, and is relative to the GUI which contains the control."
But GetAtScreenXY requires absolute screen coordinates. So you need to add GUI.X and Y to these coordinates:
GUIControl *control = GUIControl.GetAtScreenXY(gInventory.X + gInventory.Controls[startblock].X + 10, gInventory.Y + gInventory.Controls[startblock].Y - 10);
if (control == null)
return false; // or otherwise cancel the action
3) By the way, if GUIControl did not have ID parameter, your game simply would not compile. As opposed to script languages like Lua or Javascript, where you cannot detect if object has or does not have particular member before running the program, it is impossible to compile AGS Script with variables that do not exist.
Thank you again, CR.. Got it working :-D
dang mixed coordinates slipping by me again.