Using the value of an object in a list

BlitzMax Forums/BlitzMax Beginners Area/Using the value of an object in a list

The first thing you'll need to know is if a base has been clicked, to do this you need to cycle through the entity list and check if the mouse is above each base, when you get a positive result you'll know exactly which base it was.

A little example of how you might do it...
If MouseHit(1)														' if mouse was pressed
	Local This:TBase
	For This = EachIn EntityList									' cycle through each base
		If MouseInRect(This.X, This.Y, This.Width, This.Height)		' and check if mouse is above it
			This.CreateMiner()										' yes this base was clicked! lets create a miner :)
		EndIf
	Next
EndIf

Function MouseInRect(X%,Y%,W%,H%)
	Local MX%=MouseX(), MY%=MouseY()
	If MX=>X And MY=>Y And MX=<X+W And MY=<Y+H Then Return True
EndFunction