-- Game of life routine macro, before nested 'if' and 'while' were implemented. Made in August 2020. local script = [[ ; String-substitute frame and rState counters with more helpful names. alias xx fa alias yy fb alias neighbors fc alias this_cell fd * game_of_life ; Sets up the actor: finds the zone shape and copies dimensions to data table. init_zone_info goLabel g_loop ; Idle loop. Wait 1/4th of a second, then execute one GoL cycle. .g_loop 64 noop ; The entry-point for executing a cycle. .g_exec set xx = get_zone_x set yy = get_zone_y goLabel g_count_neighbors ; Count this cell's neighbors. .g_count_neighbors set neighbors = 0 ; Top-left set xx - 1 set yy - 1 position_self & set this_cell = resting_cell if this_cell == get_cell_on set neighbors + 1 ; Top set xx + 1 position_self & set this_cell = resting_cell if this_cell == get_cell_on set neighbors + 1 ; Top-right set xx + 1 position_self & set this_cell = resting_cell if this_cell == get_cell_on set neighbors + 1 ; Left set yy + 1 set xx - 2 position_self & set this_cell = resting_cell if this_cell == get_cell_on set neighbors + 1 ; Right (skip the middle) set xx + 2 position_self & set this_cell = resting_cell if this_cell == get_cell_on set neighbors + 1 ; Bottom-left set yy + 1 set xx - 2 position_self & set this_cell = resting_cell if this_cell == get_cell_on set neighbors + 1 ; Bottom set xx + 1 position_self & set this_cell = resting_cell if this_cell == get_cell_on set neighbors + 1 ; Bottom-right set xx + 1 position_self & set this_cell = resting_cell if this_cell == get_cell_on set neighbors + 1 ; Return to center set xx - 1 set yy - 1 ; Write neighbor count to an array in the owning actor. set_neighbor_count ; Go to the next cell set xx + 1 if xx >= get_zone_xw goLabel g_new_row goLabel g_count_neighbors .g_new_row set xx = get_zone_x set yy + 1 if yy >= get_zone_yh goLabel g_count_done goLabel g_count_neighbors .g_count_done set xx = get_zone_x set yy = get_zone_y goLabel g_update ; Start updating the cells based on neighbor information stored in the owning actor .g_update 1 noop ; Idle for one tick to make the update roll out gradually position_self & set this_cell = resting_cell ; Position actor based on xx and yy counters. Get tile value from resting spot. get_neighbor_count ; Read in the neighbor count for this cell coordinate. if this_cell == get_cell_on goLabel g_update_live goLabel g_update_dead .g_update_live if neighbors < 2 goLabel setDead if neighbors > 3 goLabel setDead goLabel g_update_continue .g_update_dead if neighbors == 3 goLabel setLive goLabel g_update_continue .setDead set resting_cell = get_cell_off goLabel g_update_continue .setLive set resting_cell = get_cell_on goLabel g_update_continue .g_update_continue set xx + 1 if xx >= get_zone_xw goLabel g_update_new_row goLabel g_update .g_update_new_row set xx = get_zone_x set yy + 1 if yy >= get_zone_yh goLabel g_loop ; Done execution, go back to idling. goLabel g_update ]]