Removing items from a list by number

I'm trying to actually think through things before actually coding, it seems to be a good way to improve my own logic and understanding, if this is posted I hit a snag

I'm trying to set up a horror game where people can input their own friends/family/people they know as possible victims to be randomly selected. Its intended to just be text rather than actual objects so the immediate idea is to use lists.. Would this logic work?

Using a verb

At the start have players input the name-->add to list
then ask for the names gender-->add to a second list
Any other question I could think of-- add to a third list

Works fine

That all seems very logical and easy, second thing to do is to have the first victim selected, So get a random number and set it as a variable (Will use listCount to get the max number of the list) Then Listitem using the variable number gotten earlier for each of the lists and set the results. This should keep the lists in proper order I would think so your friend Scott isn't suddenly changed to a female

Works Fine!

After the victim has been used then list remove the selected number form each list...

And this is where I fall, the very last hurdle, the normal remove from list would work alright for names, but there are probably going to be duplicates for genders so that won't work, tried mrangle's list splice function because it seemed to be able to to work around it..

Error running script: Error evaluating expression 'ListItem(game.customname,z)': ListItem: index 1 is out of range for this list (1 items, last index is 0)

n = ListCount(game.customspecies)
z = GetRandomInt(0,n-1)
pn = ListItem(game.customname,z)
ps = ListItem(game.customspecies,z)
game.z = z
msg (pn  + "The"  +ps)
ListSplice (game.customname, z, 1, null)
ListSplice (game.customspecies, z, 1, null) 

The splices are where it seems to mess up


There is no ListSplice, just do

list remove (game.customname, pn)

The error, however, suggests game.customname and game.customspecies are of different lengths.

If it was me, I would create a set of object, and give each one a name and species. Put them in a soecial room, and pick at random (PickOneChild ?), and remove it from the room when used.


The problem i see with list remove is what if there are multiples of the same species, since the way I have the list being made has the player essentially add one to each list for every entry, removing the "Wrong" one might mess up the ordering of the two lists.


As Pixie said, use Objects, as that is what they're for (multiple data/actions for a single thing: an 'Object' is a group/class/basket for holding multiple data and/or actions):

Object: victim1/npc1
Non-Script Attributes (Data): sex, quantity (of object/item), name/alias, Kingdom/Phylum/Class/Order/Family/Genus/Species/Race (mneumonic memorization: "King Paul Cried Out For Good Soup" + Race)
Script Attributes (Actions): talk, steal, attack, transactions (buy/sell/trade/haggle), etc etc etc

why would you want to have lists for each every attribute (and having to handle them: making sure their ordering and quantity stays matched up and etc handling stuff)? when you only need a list (or lists) for the objects instead

the list(s) itself(themselves) can be either: StringList + GetObject (OBJECT) === [STRING TO OBJECT], OR, ObjectList + maybe needing OBJECT.name === [OBJECT TO STRING]


Your code there looks OK to me. Are you sure the two lists are the same length to start with?

The error message quotes a line before you attempted to remove anything; it looks like your species list has multiple entries, and the name array only has one? Either that or GetRandomInt (0,0) doesn't behave sensibly when both lists only have a single item.

(though I would agree that creating objects is more efficient than dealing with the issues of Quest's lists)

@Pixie

There is no ListSplice, just do

He said in the original post that he wants to remove an element by index in order to avoid disordering the list when it contains duplicates. ListSplice is a function I posted on the forum a while back that lets you remove elements by index, or replace an element in a list without disordering it. If I remember correctly, the syntax is the same as Perl's splice function.

I can't find the code for it now, but I did some trivial tests when I posted it.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums