for...next for bullets

Blitz3D Forums/Blitz3D Tutorials/for...next for bullets

I can't figure out how to make bullets with different weapons
see, usually i do
select whichweapon5
case 1
maxbullets%=(something)
case 2
maxbullets%=(something)
etc.
default
maxbullets%=16


but then when I choose another weapon after I fire 16 bullets it says
"Array index out of bounds"


what do i do?

If you want 16 bullets and you're using a Dim variable...

Dim Bullet(15)
;or
Global Bullet[15]

the number starts at 0 and goes to 15 which means there's 16 all together. Does that help at all?

Edit:
Btw you forgot an End Select
select whichweapon5
case 1
maxbullets%=(something)
case 2
maxbullets%=(something)
etc.
default
maxbullets%=16
end select


no GIA_Green_Fire_, what i mean is,

i have lets say, 3 weapons (a pistol, with 16 bullets; a shotgun, with 8 bullets; and a sub machine gun, with 30 bullets) with the pistol it works fine, but when i choose another weapon i can only fire 16 bullets and then it says:

"Array index out of bounds"


That's what i mean

Array index out of bounds... Are you sure you are accessing them correctly.

When you create an array for instance "Dim Bullet(16)", you will actually have 16 (0 - 15) elements in the array.

The bounds of the array will be as follows...

Bullet(0)
Bullet(1)
Bullet(2)
Bullet(3)
Bullet(4)
Bullet(5)
Bullet(6)
Bullet(7)
Bullet(8)
Bullet(9)
Bullet(10)
Bullet(11)
Bullet(12)
Bullet(13)
Bullet(14)
Bullet(15)

If you tried to access "Bullet(16)", you wil get the message "Array index out of bounds"

I hope that helps.

Wrong - in blitz dim myarray(10) gives you access to 11 elements 0-10. Types are much better suited to bullet/projectile than arrays (my own preference anyway).

Matty... I stand corrected. ;)



Dim myarray(10)

For i = 0 To 10
myarray(i) = i
Next

For i = 0 To 10
Print myarray(i)
Next

WaitKey()
End