Is there a compact way to build a list from information in a table?
Say table 1 is a mixed pile of people and objects (just things in the game) and we want to build a list of just the people that are in table 1.
let peeps be a list of people in table 1
(I know this is a poor example - why not just build a new list of people in the game - but the actual thing I am trying to do is complicated and I cannot figure a way of explaining in a short post - sorry.)
I know you can loop through the table extracting people but I’m gettng loops within loops within loops and the code is getting horrible
There isn’t a faster way to do it if you are using a table. That said, I don’t think it’s as painful as you may feel it is. The extraction loop is only a few lines of code and doesn’t amount to another layer of looping unless you start running more loops inside it. To avoid that, extract the people into a list (using the loop - which then closes) then run your new procedures on the list you’ve made. You’re still now at the same level within your loops.
There are alternatives to using a table to gather your things in the first place. I don’t know if the others will suit what you’re doing. There’s a list, which is a method you’re obviously au fait with. A more different method from these two is to flag people and things with traits. And this does let you use a list-making shortcut.
For instance, I could say
A person can be unwanted or wanted. A person is usually unwanted.
Then throughout the game, I can say stuff like ‘now Sally is wanted’, or ‘now Tom is unwanted’. Then at any point I can say:
let L be the list of wanted people
and I will have them all in L, in one line, and I didn’t have to program a loop.
Now whether this method is relevant for your shenanigans, I don’t know. But I might be helpful if you hadn’t thought of it. You can also give qualities to things rather than people (meaning they can apply to objects and people, etc.) and you can use sets of qualities which have more than 2 options.
Have another look at chapter 20 of the docs, too re: lists of objects.
To decide which list is the list of (chosen objects - a description of things) in (the chosen table - a table name):
let temporary be a list of things;
repeat with item running through chosen objects begin;
if the item is an item listed in the chosen table, add the item to temporary;
decide on temporary.
This isn’t tested but it gives the basic idea. Now you can just use a one line phrase rather than rewriting the loops.