What Phaelax said ^
Here is some code, that uses types arrays and a global variable to control your object IDs (The numbers) and eventually will make programming allot easier.
Keep in mind that you can't remember all of the object names in your entire program.
Try to use variables to not get confused by all the numbers.
If all is too confusing, just use the "Number_Of_Objects" variable as a global integer. And every time you create an object, increase the global Number Of Objects variable by typing :
Inc Number_Of_Objects
And then set your object number variable to be this number.
My_Object = Number_Of_Objects
Also an addition :
If you're putting your code in a loop it will probably try to create the box a couple of 100 times a second. But the object number would be already in use, giving you errors.
Rem - The global variable for object handling.
Global Number_Of_Objects as integer = 0
Rem - Create a player type.
Type Player_Type
ID as integer
Xpos as float
Ypos as float
Zpos as float
Score as integer
Power as integer
EndType
Rem - Create a player array.
Player as Player_Type
Rem - Increase the Number_Of_Objects variable by 1
Inc Number_Of_Objects
Rem - Player variables (Can be set anywhere you like)
Player.ID = Number_Of_Objects
Player.Xpos = 329.817
Player.Ypos = 5.029
Player.Zpos = 192.839
Rem - Make a fruit type
Type Fruit_Type
ID as Integer
Xpos as float
Ypos as float
Zpos as float
Status as string
CollisionBox as integer
EndType
Rem - Set a global variable to the number of fruits
Rem - This is helpfull if you're making for-next loops elsewhere
Rem - Example :
Rem - For x = 1 to 5 would be For x = 1 to Number_Of_Fruits
Rem - It's easier to know what you're checking for this way.
Global Number_Of_Fruits as integer = 5
Rem - Create a fruit array and set it to use the fruit type
Dim Fruit(Number_Of_Fruits) as fruit_Type
Rem - Set the status variable of fruit 3 to super fruit
Fruit(3).Status = "Super Fruit"
Rem - Set the collision box object ID
Inc Number_Of_Objects
CollisionBox = Number_Of_Objects
Rem - Create some collision boxes.
For F = 1 to Number_Of_Fruits
Inc Number_Of_Objects
Fruit(F).CollisionBox = Number_Of_Objects
Next X
Do
Rem - Start the for-next-loop
For x = 1 to Number_Of_Fruits
If Object collision(Player.ID,Fruit(X).ID )>0
texture object Player.ID,11
make object box Fruit(X).CollisionBox, 100,200,50
texture object Fruit(X).CollisionBox,12
position object Fruit(X).CollisionBox, 200,300,1000
make object collision box Fruit(X).CollisionBox,-50,-50,-50,50,50,50,0
Player.Power = 20
Player.Power = Player.Power + 3000
EndIf
If Object Collision(Player.ID,Fruit(X).CollisionBox)>0 and Fruit(X).Status = "Super Fruit"
gosub endsection
EndIf
Next X
Sync
Loop