Deleting table rows

So I’ve hit a slight snag with the way my project works in a certain area (and admittedly I may just change the way it works).

I have a part of my code that, for simplicities sake doesn’t repeat through a table, but checks row 1.

choose row 1 in the Table of Enemy Items;

It then does an if to see if a Item Name entry either is not there, or is but contains “”…
if that row is empty or contains an empty string, skip item distribution.
if there is text, there’s an item waiting to be distributed so do so.

This table is empty in code:

Table of Enemy Items
Enemy(text)    Item Name(text)
with 30 blank rows

it’s populated during game play using:

choose a blank row in the Table of Enemy items;
Now Enemy entry is "Bob";
Now Item Name entry is "Gold";

The issue is, this table gives items out to enemies and such, as it does so, i want to clear out that particular entry.
So, if for example Gold gets given to Bob, then as that takes place, I do a repeat through, find Gold in the Item Name row, and now I want to effectively delete that row.

Straightforward you would say.

Blank out the whole row;

That screws up my if check though because now if any items in rows 2,3,4,5,6 etc are filled in…because row 1 is now “” “”, it assumes there’s nothing in there so no further items get distributed.

Solution I will most likely do is instead of choosing row 1, I will have to repeat through and check all rows.

The reason for the post though is…if you’re building a table dynamically…is there no way to actually DELETE a row?

The issue being…let’s say we have the following table…built dynamically in game…

Table of Items
Item Name     Room
Hammer         Garage
Saw                Shed
Wrench           Bedroom

As it works in my code…
The moment Hammer gets moved, the table becomes…

Table of Items
Item Name     Room
""                     ""
Saw                Shed
Wrench           Bedroom

What Ideally I want is row 2 to become row 1, so now theres only 2 entries in the table, not 3, where one of the 3 is now blanked out.

One thing I could do (I haven’t tested this yet but in theory it should work but it all depends on how Inform handles repeat throughs of a table that is changing.

But in theory this should grab all from the table and move it all up one.

Repeat with X running from 1 to the number of filled rows in Table of Enemy Items:
	choose row X in the Table of Enemy Items;
	if Item Name entry is there and Item Name entry is not "":
		Now EnemyNameVar is Enemy Name entry;
		Now ItemNameVar is Item Name entry;
		if X is greater than 1: [this most likely means row 1 was empty]
			blank out the whole row;
			choose row 1 in the Table of Enemy Items;
			if Item Name entry is not there or Item Name entry is "":
				Now Enemy Name entry is EnemyNameVar;
				Now Item Name entry is ItemNameVar;
				choose a blank row in the Table of Enemy Items;
				Now Enemy Name entry is EnemyNameVar;
				Now Item Name entry is ItemNameVar;
			stop the action; [No Need to rebuild the table..row 1 is still populated.]

Sorting the table in any order (including random) will always put the blank rows last, but has the obvious side-effect of reordering the table, so that won’t work if you still need the order of the rows. (And performance will probably be worse than if you simply repeat through the entire table, as well.) As far as I am aware, it’s not possible to explicitly move a table line to another position (at least not without a custom solution).

Another option would be to use a list of lists, where removing the first element from the list does cause the remaining items to “move up the queue” (see §21.11 of Writing with Inform). So you might write:

The enemy items are a list of lists of strings that varies.
[To add:]
Add {"Bob", "Gold"} to the enemy items
[To access and remove:]
let N be entry 1 of the enemy items;
let EnemyNameVar be entry 1 of N;
let ItemNameVer be entry 2 of N;
remove entry 1 from the enemy items;