-- Game of life routine macro. 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 ; Wait 1/4th of a second, then execute one GoL cycle. .g_loop 64 noop ; Count this cell's neighbors. set yy = get_zone_y while yy < get_zone_yh set xx = get_zone_x while xx < get_zone_xw 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 endwhile set yy + 1 endwhile ; Start updating the cells based on neighbor information stored in the owning actor set yy = get_zone_y while yy < get_zone_yh set xx = get_zone_x while xx < get_zone_xw 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 ; log UPDATE LIVE CELL if neighbors < 2 or neighbors > 3 ; log (SETDEAD) set resting_cell = get_cell_off endif else ; log UPDATE DEAD CELL if neighbors == 3 ; log (SETLIVE) set resting_cell = get_cell_on endif endif set xx + 1 endwhile set yy + 1 endwhile goLabel g_loop ; Done execution, go back to idling. ]]