GoneFishin
Member
Hello! I'm programming a small physics based fishing game, but have run into a challenge where a functionality I'd like to include eclipses my knowledge of GML and arrays / lists. For clarification, what I would like to simulate is the act of reeling in a fishing line by creating (and destroying) instances of the object I have called obj_String. I am at the stage in my project where everything else works fine without major errors, but I do not know the best way of integrating the create/destroy functionality with the current setup. As a disclaimer, the majority of this code was purchased from the marketplace, as I am a beginner programmer, and I have made small changes to suit the direction of this project. All comments in the code are my own.
There is a script I'm running that uses a For loop to create instances of my string object until a limit as been reached. Right now, just 5 instances of obj_String (which are only about 4 pixels long each) are created by entering 5 into the _segments variable. Please assume that the below code works as intended, and creates 5 instances, with other scripts dealing with the creation of physics joints for the edge cases (i.e where the string joins the fishing rod, and where it joins the hook).
In the following code, I am telling the game to create 5 small string segments attached with 2 physics joints each. I've edited the code to include just enough information to give a sense of how the array is coded. It runs in the create event of my game_room.
I would like to create a script that will run in a Step event called increase_length() that inserts an additional instance of obj_String at the start of this list (at position zero) bumping all other pieces down by the appropriate distances (i.e height, direction etc.). This is where I have run into a dead end. Is there a built-in function that lets me insert new information into the rp_segment array? The only lead I could find was the ds_list_insert command, but nothing I did with this command gave me what I wanted. Any guidance would be appreciated.
There is a script I'm running that uses a For loop to create instances of my string object until a limit as been reached. Right now, just 5 instances of obj_String (which are only about 4 pixels long each) are created by entering 5 into the _segments variable. Please assume that the below code works as intended, and creates 5 instances, with other scripts dealing with the creation of physics joints for the edge cases (i.e where the string joins the fishing rod, and where it joins the hook).
In the following code, I am telling the game to create 5 small string segments attached with 2 physics joints each. I've edited the code to include just enough information to give a sense of how the array is coded. It runs in the create event of my game_room.
Code:
for (i=0; i<_segments; i++) {
//the index will be at 0 the first time around as it was initialized at -1 previously.
rp_segment[rp_index, i] = instance_create(_x+lengthdir_x(_dis, _dir), _y+lengthdir_y(_dis, _dir), obj_String);
with (rp_segment[@ rp_index, i]) {
rp_number = i;
rp_id = other.rp_index;
if (i != 0) {
_inst1 = other.rp_segment[@ other.rp_index, i-1];
_inst2 = other.rp_segment[@ other.rp_index, i];
rp_joint[0] = physics_joint_revolute_create(_inst1, _inst2, _a_x, _a_y, 0, 0, 0, 0, 0, 0, 0);
rp_joint[1] = physics_joint_distance_create(_inst1, _inst2, _inst1.x, _inst1.y, _inst2.x, _inst2.y, 0);
}
}
}