How do I use vec_set or something similar for ARRAYS?

Posted By: Enduriel

How do I use vec_set or something similar for ARRAYS? - 09/16/08 11:23

Hello, I've got a problem.

What I want to do is transfer the players stats within the array to the temp array and that way control multiple npc/player/enemies stats depending on situation, it's a turn based game, worked in c-script but can't figure it out how to do it in lite-c


Code:
var player1_stats[6]; //has hp,mp,str,mgc,def,agi
var temp_defender_stats[6];



and then I have a pointer ofc for the players action called

Code:
ENTITY* player1;


I also have a temp POINTER

Code:
ENTITY* temp_defender;


Now I want to use something like this to transfer the stats to the temp array, do damage, increase stats, and then I have anotehr function which transfers the stats back to the correct player depending on who temp_defender is on that moment.

Code:
if (temp_defender == player1) {vec_set(temp_defender_stats, player1_stats);}



but it doesn't work when I use vec_set to do it. I decrease/increase the the for example HP of temp_defender, even if player1_stats is assigned to temp_defender_stats it doesn't work, but it works if I increase or decrase the stat of the player1 directly,

i've tried using this instead of vet_set but it didn't work either =/

Code:
function array_switch(var* array1, var* array2)
{
	array1[0] = array2[0];
	array1[1] = array2[1];
	array1[2] = array2[2];
	array1[3] = array2[3];
	array1[4] = array2[4];
	array1[5] = array2[5];
	array1[6] = array2[6];
	array1[7] = array2[7];
	array1[8] = array2[8];
	array1[9] = array2[9];
}

Posted By: EvilSOB

Re: How do I use vec_set or something similar for ARRAYS? - 09/16/08 13:22

try this
Code:
if (temp_defender == player1) 
{  var idx;   
   for(idx=0; idx<6; idx++)   
      temp_defender[idx]=player1_stats[idx];   //or other way round
}

should do the job
Posted By: Enduriel

Re: How do I use vec_set or something similar for ARRAYS? - 09/16/08 15:37

hmm, but i'm using 6 variables and 2 arrays:

Code:
var hp = 0;
var mp = 1;
var str = 2;
var mgc = 3;
var def = 4;
var agi = 5;

player1_stats[6]; //will contain the ones I posted above
temp_defender_stats[6]; //becomes player1_stats when it's players turn, becomes player2_stats when it is player 2s turn etc etc.


not sure how that is done with with the method you suggested :<
The reason I have a temp is because of player turns and enemy turns in a final fantasy based game, and whenever it's someones turn I tell the pointer of the player to be temp_defender

Posted By: MrGuest

Re: How do I use vec_set or something similar for ARRAYS? - 09/17/08 01:34

EvilSOB's way will work, but if you want to use vec_set, you'll need to put
Code:
vec_set(array1[0],array2[0]);
vec_set(array1[3],array2[3]);
vec_set(array1[6],array2[6]);
as you're only setting a 'vector' it will only store/copy the 1st 3 vars

Posted By: EvilSOB

Re: How do I use vec_set or something similar for ARRAYS? - 09/17/08 08:24

if you want it in a function like you suggested, try this.

Code:
function array_switch(var* array1, var* array2, var LEN)
{
   var idx;   
   for(idx=0; idx<LEN; idx++)   
      array1[idx] = array2[idx];   //make array1 = array2
}

you need to add the "len" parameter if the array is ever going to be
other than 6 elements, otherwise you could hard-code it.

You would use it like this
Code:
if (temp_defender == player1) {array_switch(temp_defender_stats, player1_stats,6);}

so if temp_defender==player1 then the temp_defender_stats will be replaced
by a copy of player1_stats.
© 2023 lite-C Forums