Carloskhard
Member
In context, in my game SIDERAL there're planets that are created procedurally.I've already code so the planets have variables which state how many of each thing they have inside (diferent types of terrains, buildings, objects...) : For example a desert planet could have a few sand mountains, some cactus and maybe an oasis.
At the time of creating those objects I'm doing this:
Where OBJ would be changed with a name for THAT especific object (for example, for a dust mountain it would be:
*All this code is executed at each planet at create event, so each planet have it's own list of objects with all the propities that are needed. Some of these propities will be use and change later at step event ;mostly; for changing the angular position of each object so they seem to be "attached" to the planet, spinning at the same rotation.(Check the SIDERAL post to see some examples).So; as you see having some way to store and acces dinamically information for each object in each planet and some propeties of each one is 100% necesarry.
With just a few objects to spawn in planets I was dealing just fine with this, but to make this code expandable I need to make all that code (which is not long) fit in a Script which would ask for the object type and the quantity to create(maybe more stuff in the future,but for now just that), so all the code above would be executed in a script which should look something like this:
So, the question and challenge now is:
HOW THE HECK DO I EVEN DO THIS?
jajaja This is exiting but I've been thinking about this and I haven't found a solution yet, so I hope some of you could help me!
So far I've considered two posible paths:
-Find a way to alter the name of a variable, for example:
And then I should be able to have a list of variables called "sand_dune[0],sand_dune[1],...,sand_dune[4]"
-Find another way to store this propities.
At the time of creating those objects I'm doing this:
Code:
///At create event of planets
for (i=0; i < OBJ_amount; i ++){
OBJ_pos_angularf[i]= random(360); //The position in the planet is measured in angles
OBJ_img[i]=irandom(NUMBER);
OBJ_scale[i] = random_range(RANGE);
OBJ_orientation[i] = choose (1,-1); //To flip X axis
OBJ[i] = instance_create(x,y,OBJECT);
if (instance_exists(OBJ[i])){ //security check
OBJ[i].image_index = OBJ_img[i];
OBJ[i].image_xscale = (image_xscale*OBJ_scale[i])*OBJ_orientation[i];
OBJ[i].image_yscale = image_yscale*OBJ_scale[i];
}
}
Code:
for (i=0; i < sand_mountain_amount; i ++){
sand_mountain_pos_angularf[i]= random(360); //The position in the planet is measured in angles
sand_mountain_img[i]=irandom(NUMBER);
sand_mountain_scale[i] = random_range(RANGE);
sand_mountain_orientation[i] = choose (1,-1); //To flip X axis
sand_mountain[i] = instance_create(x,y,OBJECT);
if (instance_exists(OBJ[i])){ //security check
sand_mountain[i].image_index = sand_mountain_img[i];
sand_mountain[i].image_xscale = (image_xscale*sand_mountain_scale[i])*sand_mountain_orientation[i];
sand_mountain[i].image_yscale = image_yscale*sand_mountain_scale[i];
}
}
With just a few objects to spawn in planets I was dealing just fine with this, but to make this code expandable I need to make all that code (which is not long) fit in a Script which would ask for the object type and the quantity to create(maybe more stuff in the future,but for now just that), so all the code above would be executed in a script which should look something like this:
Code:
create_attached_phy(object,quantity);
HOW THE HECK DO I EVEN DO THIS?
jajaja This is exiting but I've been thinking about this and I haven't found a solution yet, so I hope some of you could help me!
So far I've considered two posible paths:
-Find a way to alter the name of a variable, for example:
Code:
//At planet create event
create_attached_phy(obj_sand_dune,sand_dune,5);
//MISTERIOUS SCRIPT CODE
///create_attached_phy(object,name,quantity);
for (i=0; i < argument[2]; i ++){
"argument[1]"[1] = instance_create(x,y,argument[0]);
....
-Find another way to store this propities.