structures

Rob Cozens rcozens at pon.net
Mon Mar 8 12:35:22 EST 2004


>For example, one of my students wants to create an array
>of bullets for his video game.  For each bullet we need to
>know the following:
>  - its current availability (already in use, or available)
>  - its movement in the x direction if in use
>  - its movement in the y direction if in use
>
>We could use three parallel arrays, but it seems cleaner to
>use a struct.  Is it possible?

Hi Marty,

The short answer to your question is "no".

Longer answer:

* By "structure", I presume you mean a record variable with multiple 
fields that can be addressed individually.

* Perhaps your student might consider using properties.  Example: a 
radio button or check box's hilite property already tells you if the 
button is available (hilite = false) or selected (hilite =  true). 
One could use an existing button property (eg: armed or hilited or 
disabled) or set a custom property for each bullet.

* You could use 1 array with three items in each value:

put (the hilite of me)&comma&(the loc of me) into bulletArray[bulletNumber]


* How are the bullets moved?  If a bullet were to store it's position 
after each movement, it could calculate x & y movement:

	on bulletMoved
		put the loc of me into newLocation
		get the oldLocation of me
		put (item 1 of newLocation) - (item 1 of it) into xMovement
		put (item 2 of newLocation) - (item 2 of it) into yMovement
		set the oldLocation of me to newLocation
	end bulletMoved


-- 

Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.net/who.htm

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)


More information about the use-livecode mailing list