Page 1 of 1

arrays

PostPosted: Thu Jun 07, 2012 10:53 am
by BogdansB
Hey,

I made an array in the "global code"

Code: Select all
int weapon[15];


there i made this

Code: Select all
weapon[0]= 3 - round(rand(3));


so i want to make for every weapon another damage number.

but something goes wrong... I want to have a variable wich gets different when you have another weapon (weapon[0],weapon[1]....)


how can i do it?
can i out the variable in int?
when i try it , it makes the value 0 :S he beats "0" every time

Re: arrays

PostPosted: Thu Jun 07, 2012 3:30 pm
by skydereign
You have to set the other values in the array. Since you declared the weapon array to be size 15, you have 15 weapons to choose from. In your code though you only set one of them. So just say you wanted the weapon's power to increase for the next weapon (weapon one).
Code: Select all
weapon[1]=5-round(rand(3)); // this weapon has a range from 2-5

You can automate through a loop the setting of all weapons.

Re: arrays

PostPosted: Thu Jun 07, 2012 4:10 pm
by BogdansB
I just want to write for every weapon another code so i thought that if i make an array I could write for every weapon smth.

Code: Select all
weapon[1]= 5;
weapon[2]= 2;
weapon[3]= 34;
weapon[4]= 7;
...



and if i write this round rand thing , do i need to put it into int or char?

Re: arrays

PostPosted: Thu Jun 07, 2012 4:45 pm
by skydereign
rand returns a double, and round will convert that into an int. However you can set a char or int equal to an int, and it would still work. However you want it to be an int, so use an int.