arrays

Learn how to make certain types of games and use gameEditor.

arrays

Postby BogdansB » Thu Jun 07, 2012 10:53 am

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
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: arrays

Postby skydereign » Thu Jun 07, 2012 3:30 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: arrays

Postby BogdansB » Thu Jun 07, 2012 4:10 pm

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?
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: arrays

Postby skydereign » Thu Jun 07, 2012 4:45 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest