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

random arrays?

Root / Programming Questions / [.]

KomodoCreated:
so i'm trying to make random generated enemys and the way how im doing it is very time consuming and i was wondering if you could make some arrays like n$="ninja" and a$="archer" then make another that randomly picks the arrays like the rnd command but for arrays instead of numbers. if you could help me i would greatly appreciate it thx :)

How are you doing it now?

i have a random number between 0 and 3 and i do a if command every time i need it like
c=rnd(3)
then I do
if c==0 then ?n$ ;"chlalenged you to a battle"
or like when i need it for stuff like atk i do
if c==0 then atk=50
and doing it that way can be very time consuming when you have a bunch of enemys.

if you want to see the full code just look at my program.(turn based battle)

So what you're doing now is something like c=rnd(3) if c==0 then atk=50:def=20... if c==1 then atk=30:def=80... if c==2then atk=90:def=10... ... and you want to use arrays instead? You could have a 2D array:
DIM ENEMIES[numberofenemies,3] 'enemies have 3 variables in this example, ATK, DEF, and SPD
DATA 50,20,30
DATA 30,80,20 'example data
DATA 90,10,40
'DATA attack,defense,speed

FOR I=0 to numberofenemies-1 'enemy number
 FOR J=0 to 2 'stat number
  READ ENEMIES[I,J] 'store data in array
 NEXT
NEXT
To put the data into an array, and then
C=RND(3)
ATK=ENEMIES[C,0] 'attack is the 0th piece of data
DEF=ENEMIES[C,1] 'defense is the 1th piece of data
SPD=ENEMIES[C,2] 'speed is the 2nd piece of data
to recall it

Yes thats perfect thanks I never understood the dim command but know it's starting to make since so you killed two birds with one stone thanks so much for your help. But one question if I just wanted to subtract my hp by how much his attack does how whould I do that?

Yes thats perfect thanks I never understood the dim command but know it's starting to make since so you killed two birds with one stone thanks so much for your help. But one question if I just wanted to subtract my hp by how much his attack does how whould I do that?
DEC HP,ATK DEC HP,ENEMIES[C,0]

oh ok you were just showing me two ways of doing it well thanks so much you are a program saver this is going to help me allot thanks again :)

hey one more Question how do i put text in it?

I haven't really used text arrays very much, but I think you'll need a separate array: NAME$[numberofenemies] DATA "enemy1","enemy2",etc. FOR I = 0 to numberofenemies-1 READ NAME$ NEXT

12Me21 beat me to it. You can't mix numbers and strings in one array. If you're looking to build a large scale project: This is basically the theory behind Lowerdash. It builds the data arrays for you and maps names to the indexes. (Of course your code will be faster) Edit: shameless plug

oh that why it won't work thanks everybody again you guys are a huge help :)