Does quest have something similar to the includes() function? For instance, if I want to do something like:
if(player.species.includes("a"))
do you mean in terms of 'arrays' ??? (aka, does an array have this item?)
(lists === arrays, more or less)
then, yes:
http://docs.textadventures.co.uk/quest/functions/listcontains.html
http://docs.textadventures.co.uk/quest/functions/dictionarycontains.html
example_stringlist_variable = Split ("red;blue;yellow", ";")
if (ListContains (example_stringlist_variable, "blue") {
msg ("BLUE")
} else if (ListContains (example_stringlist_variable, "green") {
msg ("GREEN")
}
and if you want to return the item's value:
http://docs.textadventures.co.uk/quest/functions/stringlistitem.html
http://docs.textadventures.co.uk/quest/functions/stringdictionaryitem.html
also, I think the current version of quest, also now uses the normal index method of most programming languages:
I don't now what the exact syntax/Function/Script name it is, so this is jsut a conceptual example
returned_item_value = LIST (INDEX_POSITION)
(hopefully someone else can provide the actual Script/Function for you)
you can also check/get any nested Object (any level of Object within an Object):
http://docs.textadventures.co.uk/quest/functions/contains.html
http://docs.textadventures.co.uk/quest/functions/getallchildobjects.html
http://docs.textadventures.co.uk/quest/functions/getdirectchildren.html
there's also the 'Scope' Scripts/Functions too:
http://docs.textadventures.co.uk/quest/functions/#scope
and a ton of more functionality too...
http://docs.textadventures.co.uk/quest/
http://docs.textadventures.co.uk/quest/elements/
http://docs.textadventures.co.uk/quest/types/
http://docs.textadventures.co.uk/quest/null.html
http://docs.textadventures.co.uk/quest/elements/object.html
http://docs.textadventures.co.uk/quest/scripts/
http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (alphabetical order)
and a lot more...
Oh, thanks! I guess I should have been more specific.
I'm more interested in finding out what characters are in a string. For instance, if I were looking to see if a string contained "an", this could return true for "human", "ant", "plant", and so on.
ah okay, look at the 'string functions':
http://docs.textadventures.co.uk/quest/functions/#string
specifically some of them are:
// these can be used for find a specific sub-string within a string, as you want to do:
http://docs.textadventures.co.uk/quest/functions/string/instr.html
http://docs.textadventures.co.uk/quest/functions/string/instrrev.html
// -----
http://docs.textadventures.co.uk/quest/functions/string/startswith.html
http://docs.textadventures.co.uk/quest/functions/string/endswith.html
http://docs.textadventures.co.uk/quest/functions/string/left.html
http://docs.textadventures.co.uk/quest/functions/string/right.html
http://docs.textadventures.co.uk/quest/functions/string/mid.html (this is probably the most powerful/useful of all of them)
and there's also the 'for', which can be used for strings too:
http://docs.textadventures.co.uk/quest/scripts/for.html
(the below is from the link above)
Generally, foreach offers a neater way of going through a list, but 'for' can be useful for iterating through a string. This example will print each character in the string, together with its position:
s = "Hello World!"
for (i, 1, LengthOf(s)) {
msg(i + ": " + Mid(s, i, 1))
}
You can use Instr
, which will return 0 if "a" is not in the string
if (Instr(player.species, "a") > 0)