J
Joe Banko
Guest
I would like to pull data from an array which I am reading from a text file I created. Below is the code I use to pull the data into the array from a tab-d text file.
Now that I have an array I would like to pull the data out using the first "column" which has a unique name in it. How do I pull the values out of the line which matches the first column? For instance my first entry into the array would be spear and I want to do something like:
In my macros file I have defined which columns relate to the projectile:
GML:
//projectile array
projectiles = array_create(3);
//projectile file location!!!!!
projectilefile = working_directory + "projectiles.txt";
//point to text file
var rline, bogus
fid = file_text_open_read(projectilefile);
if fid {
for (var i = 0; i<3; ++i)
{
//make a projectile entry
projectiles[i] = file_text_read_string(fid);
file_text_readln(fid);
}
file_text_close(fid);
var bogus2 = 1;//for debug breakpoints
}
Code:
if projectiles[@spear",P_ENABLED]
{
hspeed = projectiles[@"spear", P_SPEED];
sprite_index = projectiles[@"spear",P_SPRITE_INDEX];
projectile_damage = projectiles[@"spear",P_DAMAGE];
...
...
}
Code:
//projectile
#macro P_ID 0
#macro P_LAUNCHER 1
#macro P_SPRITE_INDEX 2
#macro P_IMPACT_INDEX 3
#macro P_RANGE 4
#macro P_SPEED 5
#macro P_FIRE_DELAY 6
#macro P_FRICTION 7
#macro P_WEIGHT 8
#macro P_DAMAGE 9
#macro P_HEAD 10
#macro P_TRAIL 11
#macro P_FIRE_SND 12
#macro P_IMPACT_SND 13
#macro P_ENABLED 14