So, why do we need an identifier anyway? Well, we may have different types of information that we’re tracking that require the same values. Let’s use an example of space ships. You have your good guy ship and all of your bad guy ships, plus you’ve got freighters and destroyers. They all have a name, laser power, shield power, armor, missile compliment, speed, etc. So why would you want to create a different TYPE for each one? Just use one and use different identifiers. Type Ships Field Name$ ; name of this ship Field LaserPower% ; 1-20 points per hit Field Armor% ; 100-150 points Field ShieldPower% ; 150-300 points-adds to Armor Field Missiles% ; 5-50 depending on ship type Field TopSpeed# ; 2.00–3.50 based on ship type End Type Now, instead of having to create three (or many more depending on the number of ship types you have) complete TYPE constructs, you can use three separate identifiers. PlayerFighter.Ships = New Ships BadguyFighter.Ships = New Ships Freighter.Ships = New Ships Destroyer.Ships = New Ships Each one can now be accessed directly and assigned values that will only be applicable to the identifier that they are associated with. That saves some major headache, believe me! |
Well, the headache is back. Turns out that while you can certainly do what I'm showing above, you *can't* use the identifiers to snag them directly. I thought I'd tested this, but apparently I missed it.
If, for example, you filled up those Types with 100 various ships and you wanted to print the names of ONLY the Destroyers...you can't without somehow flagging them.
So the following:
For Destroyers.Ships = Each Ships Print Destroyers\Name$ Next |
Would print ALL 100 ships, not just the Destroyers.
So, here's ONE way to handle it using flagging. I know there are other ways to flag, but this way seems easy enough for most to grasp:
Graphics 640,480 SetBuffer BackBuffer() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; setup consts for ship flags;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Const PlayerFighter = 0 Const BadGuyFighter = 1 Const Freighter = 2 Const Destroyer = 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; setup a currentship flag ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Global CurrentShip = PlayerFighter ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; type defination ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Type Ships Field ShipType ; What kind of ship is it? Field Name$ ; name of this ship End Type ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; initialize a bunch of ships;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; For i = 0 To 24 Ship.Ships = New Ships Ship\ShipType = PlayerFighter Ship\Name = "PlayerFighter" + i Next For i = 0 To 24 Ship.Ships = New Ships Ship\ShipType = BadGuyFighter Ship\Name = "BadGuyFighter" + i Next For i = 0 To 24 Ship.Ships = New Ships Ship\ShipType = Freighter Ship\Name = "Freighter" + i Next For i = 0 To 24 Ship.Ships = New Ships Ship\ShipType = Destroyer Ship\Name = "Destroyer" + i Next ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; main program;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; While Not KeyHit(1) Cls If KeyHit(2) CurrentShip = PlayerFighter EndIf If KeyHit(3) CurrentShip = BadGuyFighter EndIf If KeyHit(4) CurrentShip = Freighter EndIf If KeyHit(5) CurrentShip = Destroyer EndIf Locate(0,0) Print "1=PlayerShips, 2=BadGuyShips, 3=Freighters, 4=Destroyers, ESC = Quit" Print For Ship.Ships = Each Ships If Ship\ShipType = CurrentShip Print Ship\Name EndIf Next Flip Wend End |
Well, I must have been a little nutty that day cause I could swear he said they were 8 bytes. I even recall testing things out in the DataBank area and confirming that myself, go figure.
Anyway, bottom-line is that FLOATs are 4 bytes wide, not 8. Thus, you should use (see Page 95):
PokeFloat MyBank,0,100.175 PokeFloat MyBank,4,200.25 |
...instead of using "PokeFloat MyBank,8,200.25" on the second line. And, also, make sure to use 4-byte offsets when using PeekFloat.
So please refer to the following link for full details on the new method I'm using, and snag the code too:
Handling Sprites on Scrolling Tiled Backgrounds with Collisions
Hope that helps!