indexOf in lists?

cm97878
Is there a function to get the index of an item in a list? Or do I need to make such a function myself? I've done a fair few searches, and simply typing 'object.indexOf("something")' doesn't appear to work. If I'm just an idiot and missed a simple way, sorry about this.

The Pixie
No.

And Quest does not support the dot operator, so it would be:
IndexOf(object, 'something')

jaynabonne
You can check if an item is in a list with ListContains, but I don't see a built-in function that returns the actual index. If I may ask, what do you need the index for? Perhaps there is another way to accomplish what you want.

cm97878
Well, in essence I was going for a sort of limited 'teleport' ability that would allow the player to teleport to certain locations. I just used to identically-named commands: They can type the keyword alone to get a list of unlocked locations, read from a stringlist, and then be prompted for their choice; or they can simply type the keyword and the location if they already know it. The way I was going to do it likely isn't going to work now, so I'm wondering if this concept at least would: When they 'unlock' a location, add the name to the stringlist, and then add a similar item to a string dictionary? The key would be the name they would type, and the value the name of the destination? That way it can display them from the list, reference the dictionary, and get the destination from the value. This is just the first thing that came to me, now that I've gotten some sleep and it's not 3am, but I don't think I quite understand string dictionaries yet, as I'm unsure if this would work.

jaynabonne
If you're looking for a mapping from string to string (e.g. source to destination), then a dictionary would work well.

If you only need the string list to hand off to the menu code, then you can just build it on the fly at the point you need to run the menu by using "foreach" over the dictionary to get each key into a temporary list for the menu. That way you don't have to maintain two parallel data structures.

cm97878
The string list is just to display the possible locations, but I've simplified it quite a bit so it doesn't depend on them being parallel or anything. Thanks for the help, guys.

HegemonKhan
I don't know if this is the design that you want, but here's a design for doing transportation without using Exits ("teleporting/warping"):

viewtopic.php?f=18&t=5138 (Explore and Travel Code by HK)
(this is old code, so it's not the most efficient, as I got confused with some parts of it, but it does work)

and if you need any help on using Lists/Dictionaries:

viewtopic.php?f=18&t=5137 (Using Lists and Dictionaries Guide by HK)

ask if you need any help

----------

about getting the index value:

you could always make your own function to do so

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

Support

Forums