LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Deleting Items From Array

Root / Programming Questions / [.]

ninjagnuCreated:
I have a multiplayer asteroids game that I've been working on for a little while. The multiplayer works and I can see the other players etc. But I'm having a few problems with arrays. How do I delete an item from an array? I've solved this so far by making a simple 1d array and then allocating space for the bullets based on flags. like this: 0 <-- unallocated space. 0 0 0 1 <--- allocated space 1234 5678 123
DEF ALLOCATE B,X,Y,A OUT DID
 VAR I=0
 WHILE I < LEN(B)
  IF B[I] == 0 THEN
   B[I+1]=X
   B[I+2]=Y
   B[I+3]=A
   RETURN TRUE
  ENDIF
  INC I,4
 WEND
 RETURN FALSE
END
The code then loops through the array and tries to assign a bullet to some unallocated space. This works well when there are only a small amount of bullets on screen right now I'm using an array with 64*4 indexes. But it will stop working when more than 64 bullets are on screen. How instead do I delete an item from the array at any index? This would solve my need for an allocation function and make my code much cleaner.

Here are some functions for inserting and removing elements from arrays: https://smilebasicsource.com/page?pid=813