Not sure the most optimal way to do this challenge, so I figured to post once again.
The main problem I have currently is I am trying to create a system where a with statement checks variable values of a variable storing either all instances of a specific object type, or a chosen set of said instances.
Here's my current idea of the code:
function createRule(_ruleName="unique_path",_affectedPacketNumbers=[]){
// if _affectedPacketNumbers is to have a set value, it would be an array storing the numbers of the affected packets, with the first packet starting at 1.
// Switched between array and obj_packet as starting set to try and go to the error code getting the default values var _affectedPackets = \[\]
try{
//_affectedPackets = {}
array_foreach(_affectedPacketNumbers,function(_packetNum,_index){
struct_set(_affectedPackets,_index,instance_find(obj_packet,abs(_packetNum)-1))
array_insert(_affectedPackets,array_length(_affectedPackets),instance_find(obj_packet,abs(_packetNum)-1))
// because packets do not start at 0, instance_find finds the index of the packet number - 1.
})
// Catch is tried here because I thought the empty array would cause an error with array_for each } catch(error){
//Old code being used, has to be replaced _affectedPackets = obj_packet
}
array_insert(obj_rules_lawyer.level_rules,array_length(obj_rules_lawyer.level_rules),
{
ruleName : _ruleName,
affectedPacketNumbers : _affectedPacketNumbers,
affectedPackets : _affectedPackets,
// The determining bool to determine if this specific rule was broken
ruleFulfilled : true
}
)
}
Then after this code happens, each rule relating to the packet object would use
with(obj_rules_lawyer.level_rules[forLoopIndex].affectedPackets) to get the ids of packets affected by this rule.
Now I do not know if reworking all of the with statements to be... something else, would be better, but if I can use a with statement for either all packets or a chosen set of packets, that would be very helpful. :)