So I have this code, the part that isn't working is in func move_turn_order(). When I have it directly using the array arr_ship there isn't a problem to run the code, I just wasn't able to properly reset array (probably a way to do this that I am unaware of). So I use a duplicate to keep the original from being changed, that way my thought was I could reset at the end of my code back to the original again as the template once all my ships have been removed. The problem seems to be for me that it doesn't apply the
if arr_ship_2[i].movement == 0:
but rather it keeps going into negative movement. Is there a reason that when it is using the duplicated array that it isn't measuring when the movement becomes 0, because when I use print(array_ship_2.movement) it shows the movement changing.
@onready var arr_ship = get_tree().get_nodes_in_group("spaceships")
var turn_move = 0
var turn_attack = 0
func _process(_delta):
if turn_move == turn_attack:
move_turn_order()
elif turn_move > turn_attack:
attack_turn_order()
func move_turn_order():
var i = 0
var arr_ship_2 = arr_ship.duplicate(false)
var ship_active = arr_ship_2[i].active != false
var ship_inactive = arr_ship_2[i].active == false
var ship_empty = arr_ship_2.is_empty()
var the_unit = arr_ship_2[i]
var curr_pos = the_unit.position
if ship_inactive:
arr_ship_2[i].active = true
if ship_active:
if Input.is_action_just_pressed("accelerate"):
the_unit.global_position += Vector2(1,0).rotated(deg_to_rad(the_unit.rotation_degrees)) * 128
arr_ship_2[i].movement -= 1
if Input.is_action_just_pressed("decelerate"):
the_unit.global_position = curr_pos + Vector2(-1,0).rotated(deg_to_rad(rotation_degrees)) * Vector2(128,128)
arr_ship_2[i].movement -= 1
if Input.is_action_just_pressed("rotate_left"):
the_unit.rotation_degrees -= 60
arr_ship_2[i].movement -= 1
if Input.is_action_just_pressed("rotate_right"):
the_unit.rotation_degrees += 60
arr_ship_2[i].movement -= 1
if arr_ship_2[i].movement == 0:
arr_ship_2.pop_at(i)
if ship_empty:
arr_ship_2 = get_tree().get_nodes_in_group("spaceships