How to reference a specific string in a string list?

Shadecerule

When checking if the player's input matches a string in a list, I want to use the position of the string instead of the contents of the string. For instance:

ShowMenu ("", choiceList, true) 
{
    if (result = choiceList[0]) 
    {
        msg ("choice 1")
    }
}

However, what I entered above doesn't seem to be working because of choiceList[0].

The main reason for my question is that I want my menus to have both dialogue and actions within a single menu, such as:

1: "That was rude."
2: Hit him.

And it seems that if statements aren't very friendly with quotations in strings, so I'm looking for an alternative method.

Thanks in advance to anyone can help me figure out how to accomplish this!


The Pixie

This is an oddity of Quest. It does not know what type of thing choiceList[0] is, it could be a string, it could be an object, and at first it is kind of neither. So you are comparing a string, result to a thing of indeterminate type, choiceList[0] which will never match. If you do something with the value, that will get is set to be a proper type, so you could do this:

ShowMenu ("", choiceList, true) 
{
    s = choiceList[0]
    if (result = s) 
    {
        msg ("choice 1")
    }
}

Or you could use a function that will return a string:

ShowMenu ("", choiceList, true) 
{
    if (result = StringListItem(choiceList, 0)) 
    {
        msg ("choice 1")
    }
}

Log in to post a reply.

Support

Forums