TonyBowlin Posted March 22, 2018 Share Posted March 22, 2018 So my basic Idea here is to take controls for CONTROL_FWD/BACK/LEFT/ and RIGHT. However, I don't want anything to happen such as llPlaySound untell a combo chain of these controls had been inputted such as hitting the back key three times then playing a sound. Anyone know of a way to do this? Link to comment Share on other sites More sharing options...
Love Zhaoying Posted March 22, 2018 Share Posted March 22, 2018 You will need to put variables in your script to count/keep track of the various key presses. I suggest a timer to reset the variables if sequence is started, but not finished in the desired time. (Or get script time at start, and subsequent key presses, reset flags if too much time has passed.) Link to comment Share on other sites More sharing options...
TonyBowlin Posted March 22, 2018 Author Share Posted March 22, 2018 I also wanted to do different combinations of controls like BACK,BACK,BACK and BACK,BACK,LEFT Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 22, 2018 Share Posted March 22, 2018 In your control event, you can choose to filter for only those key presses that start an action, as opposed to key presses that are held or released. So just count how many key presses the script has sensed in a specific time frame. For example, if you want to play a sound ONLY when there has been a double key press within one second, you could write control(key id, integer level, integer edge) { integer start = level & edge; if ( (CONTROL_UP & start) && llGetTime() > 1.0 ) { llResetTime(); } else if ((CONTROL_UP & start) && llGetTime() <= 1.0) { llPlaySound (strMy_sound, 1.0); } } Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 22, 2018 Share Posted March 22, 2018 3 minutes ago, TonyBowlin said: I also wanted to do different combinations of controls like BACK,BACK,BACK and BACK,BACK,LEFT That's getting to be very cumbersome, so I would recommend against doing anything like that, but in theory anyway you could do exactly what I just suggested. Just keep track of counts of specific types of clicks in separate counters and check to see when you have the correct ones. It's all a matter of working through the logic of what you want to do. Link to comment Share on other sites More sharing options...
TonyBowlin Posted March 23, 2018 Author Share Posted March 23, 2018 Well, I'm making a playable Ocarina. so when a correct song is played it triggers something, but haven't gotten that far yet. Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 23, 2018 Share Posted March 23, 2018 Good luck with it. That sounds like an interesting logic challenge. Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted March 23, 2018 Share Posted March 23, 2018 (edited) The way I would do (and did) this is using strings! (Even though the Ocarina is a flute.) I can post my script if you're having trouble, but this should get you started: Take controls, obviously. Use a global variable string to hold a button combination. Each time a key is pressed (held&edge), add to the combination. Use a timer to clear the string if the user takes too long to play the next note. Use a global variable for each complete song, and check if the combination matches any of those. Edited March 23, 2018 by Wulfie Reanimator 2 Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted March 23, 2018 Share Posted March 23, 2018 (edited) @Rolig Loon In response to one of your posts, lists are not required nor are they nearly as good as strings for something like this. (My first thought was lists too.) The reason why using a list for holding input/song combinations doesn't work is primarily the fact that you cannot compare the contents of lists to see if they match in LSL, unless you fully loop through both lists. While that's not a big problem for small lists, it's more code to write that does unnecessary things. You can and should use strings here instead because you can easily compare their exact contents. list combination = [1, 2, 3]; list song = [4, 5, 6]; if(combination == song) { // This happens, but it shouldn't. llOwnerSay("They match!"); } Edited March 23, 2018 by Wulfie Reanimator Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 23, 2018 Share Posted March 23, 2018 I agree. My suggestion above had to do purely with the mechanics of identifying separate key presses, so that you can tell not only what was pressed but in which order. There are several ways that you might store the information and compare it with an expected sequence. By trapping the sequence of key presses, you are essentially "spelling" a word, which is a string. As you said, it makes sense to compare that string with another expected string to see if they match. That is indeed more efficient than comparing elements in lists. Another way meet the challenge might be to assemble the information as an integer and then use an expected integer as a mask to see whether they match. It might be interesting to try several different approaches. Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now