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 :)
random arrays?
Root / Programming Questions / [.]
KomodoCreated:
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=50and doing it that way can be very time consuming when you have a bunch of enemys.
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 NEXTTo 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 datato 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?DEC HP,ATK DEC HP,ENEMIES[C,0]
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