Converting Player Input Into A List
Liam315
01 May 2013, 17:36Basically, I'm building a fight sequence in which I want to lock the player into the sequence and prevent them from executing normal commands like look at, take, go north, etc. (which I've done using get input and looping the function on itself) and use a switch for what does and doesn't get a response. The limiting factor of the switch though is that the input has to match what I have exactly.
What I would like to do is parse what the player has entered and see if any of the words match any of my switch cases. My initial idea was to create a list containing the verbs used in the switch, then compare all the input words to see if any are on the list and run them if so. But I don't know how to convert what the player wrote into an itemised list, all my experiments with the split function have failed miserably.
Is there any way I can get around this? It's no big deal if I can't, I can simply explain that only single verbs are needed for the fight, but I'd like to give some flexibility in what the player writes to make it more natural if possible.
What I would like to do is parse what the player has entered and see if any of the words match any of my switch cases. My initial idea was to create a list containing the verbs used in the switch, then compare all the input words to see if any are on the list and run them if so. But I don't know how to convert what the player wrote into an itemised list, all my experiments with the split function have failed miserably.
Is there any way I can get around this? It's no big deal if I can't, I can simply explain that only single verbs are needed for the fight, but I'd like to give some flexibility in what the player writes to make it more natural if possible.

jaynabonne
01 May 2013, 17:56My first thought was to use Split, so if that wasn't working, I'm curious to know what you did and how it didn't work. Would you be able to provide what you had tried (it might just be a simple correction needed).
Otherwise - are you just looking to break the input up into "words" based on spaces as separators? And is your input going to be simple "verb" or "verb object" patterns?
Otherwise - are you just looking to break the input up into "words" based on spaces as separators? And is your input going to be simple "verb" or "verb object" patterns?

jaynabonne
01 May 2013, 17:58If you wanted to get fancier, there is also the Populate API, which matches based on regular expressions.
http://quest5.net/wiki/Populate
If you'd like to pursue that, we could get into more detail.
http://quest5.net/wiki/Populate
If you'd like to pursue that, we could get into more detail.
HegemonKhan
02 May 2013, 01:58would you need to create and add to a list ?
instead of using split:
instead of using split:
get input {
your_input = result
If (not Combat_List.your_input) {
Combat_Input_List = NewStringList
List Add (your_input)
show menu ("What is your combat choice?",split (Combat_Input_List),true) { // or whatever you want to do
// etc etc etc
}
} else {
msg ("that's already one of your combat options")
// I'm missing the condition of if the input is not valid, but you can probably get it added in yourself
}
Liam315
02 May 2013, 05:08jaynabonne wrote:Otherwise - are you just looking to break the input up into "words" based on spaces as separators?
This. My switch cases are all simple verb patterns, it's a bare fist fight so no other objects are involved. So if the player types in "punch man in head" I want the script to be able to extract "punch" from that sentence and ignore the rest of the words.
I've deleted all the split things I tried so I can't remember exactly what I had, but this is my first attempt at using split so a simple error somewhere is likely. My biggest confusion is where should "split" come in relation to the rest of the code. My impression from the wiki was I should either add the whole string to a named list and then split it. If I split the input to begin with, I don't know how to add it to the list I've created. Everything else in the code works (foreach, if listcontains etc.) but I get stuck around:
Get Input, then:
findverb = NewStringList()
list add (findverb, result)
split (findverb, " ")
I realise that third line would try and call a function and so wouldn't work, I used it in different ways but I wanted to show how I tried to use the space as the string separator.

jaynabonne
02 May 2013, 08:54Basically, given the input string in "result", you'd have:
It breaks the line up and returns a list to you. Then you can do ListContains(list, "punch") (for example) to check for the words you want.
list = Split(result, " ")
It breaks the line up and returns a list to you. Then you can do ListContains(list, "punch") (for example) to check for the words you want.
Liam315
02 May 2013, 09:13Got it working
. Thanks once again Mr Nabonne, you truly are the resident coding guru.
