Menu Blues, [SOLVED]

1 favourites
  • 13 posts
From the Asset Store
A post apocalyptic music pack with 12 main themes and 12 in-game loops
  • So I have been developing a game for roughly the last two months and am nearing a finished product, however, I have hit a brick wall trying to implement a song selection menu.

    The Basis: my game is meant to play, die and play again, so I do not want the gameplay to get repetitive from the music getting old (especially considering the way the game is designed, certain levels take more time to get past)

    The Solution: My original problem was that my first idea to create a menu basically just sets one variable true and all others false and tells it what to go to if right arrow key is hit or left arrow key is hit (basically just forward and back) however, this worked occasionally but for the most part what I ran into was the process would jump past the desired variable and go to the end. Essentially because it would [on arrow key hit] go to next, go to next, go to next, etc... until the end as it would continuously set one the next variable to true onward through the list.

    The only solution I have seen posted to create a menu that A) can be navigated through with the keyboard/touch controls and B) is in a cyclical loop so that it always refers to the next and previous song on the list (essentially just something that tells the game which item is selected and what items will be selected if either arrow key is triggered) requires a "For" statement that interferes with the music playing.

    The Problem: The real problem lies in the fact that the only menu that seems to be possible to create in Construct relies on a "For each" statement. It relays two object's position to the console and determines what is selected based off its current position in relation to eachother. This leads to an issue though where every time the player cycles through the menu it plays the intended song, however, it repeats infinitely from the start (roll your tongue, it sounds like that) my theory is it is being interfered with by the "For Each" statement that the menu relies on causing it to select the song over and over repeatedly from the beginning

    (example of the code for the menu above)

    The way that the song selection actually works is I essentially just paired the song selection with said menu option and made the menu invisible. So using the same idea as before, if ___ is selected in the menu, then ____ song is activated (set songpic animation to ___ frame, set song__ variable to true, set song__ variable to false x2 (for both the song before and the song after))

    So basically, what I'm really wondering and hoping for here, is there a way to make a cyclical menu that one can control with the keyboard/touch input that doesn't rely on a "For" statement? I'm not sure how this would be accomplished as you assumably need the "For" statement to test the position of the marker to the menu item, and from what I have found, that is the only way to make a menu like this.

    P.S. section: I will mention, as I said above, the original solution did work occasionally, however, it was odd and hard to pinpoint what was working and what wasn't. But for the sake of trying to come up with solutions I will attempt to explain the best I can.

    On one attempt, I finished the menu by having 13 different songs to choose from, if you were on or otherwise (global variable) SongOne is true, then set SongTwo to false and SongThirteen to false, if on SongTwo is true then set SongOne and SongThree to false, if SongThree is true then set SongTwo and SongFour to false, so on so forth through the whole list so that the previous and next song would always be set false once you arrive on the selected song (this prevents overlay from the previous song). Then I simply set it so if the SongSelectionMenu (also global variable) menu is true (activated if you select it from the pause menu ((that section works fine))) then set SongOne to true.

    Now here's where it gets weird, first the menu worked perfectly as intended if you were to only go back through it (IE 1,13,12,11,10,9,8,7,6,5,4,3,2, and 1), however if you went forward on it it would always go back to 1, and more-so if you were on 1 it would always skip to 13 if you were to attempt to go forward one song.

    On another attempt, none of really worked (this was for a different menu but same concept in the problem I was facing) however, this time I set it so that it only activated the Song__ variable IF BOTH the other two variables were also false. That didn't really work, but then I started deleting different conditions in various patterns and undoing them until something worked, AND IT DID! somehow...

    I don't really get it but with a strange combination of If true AND also if ____(s) false conditions the menu went through three selections (out of four) correctly, for some reason the fourth was disabled. However I had a power outage and was neither able to save the work nor continue testing why that solution was working.

    So Hopefully maybe these last few notes can maybe get the ol' brain juices flowing for anyone looking to help me create a new way to make a menu in Construct, or hopefully maybe someone knows something I don't. I'm only a novice when it comes to programming.

  • Below is an example of the menu I was working on, again, it only somewhat works, this time though it is only barely working going back (Again, it should go 1,13,12,11,10,9,8,7,6,5,4,3,2,1 going back, however at the moment it is going 1,12,11,10,9,12,11,12,11,10,12,11,10,9,etc...)

  • I have also managed to get the menu to work going forward from Song One to Song Two through the addition of more global variables, however, I am unable to figure out how to continue this to work for every song in the list from 1 to 13, in the example posted below, the menu still has the aforementioned issues going backwards, however, now if you hit the right key from Song One it will go forward in the list to "Song Two" and no further.

  • I would just have a global variable that starts at 1, and when you press right arrow, it adds 1 to the variable and each number relates to a song. You can also relate the same variable to animation frame.

    pseudo something like :

    global int track = 1

    On right arrow pressed, stop audio, add one to track

    On left arrow pressed, stop audio, subtract one from track

    If track > 13, set track to 1

    If track < 1, set track to 13

    songcho, set animation frame to track

    If track = 1, play song 1

    If track = 2, play song 2 etc

  • thank you, i have tried doing something like this several times I didn't think about the

    If track > 13, set track to 1

    If track < 1, set track to 13

    that's easily the best solution to creating this loop, thank you so much, I'm implementing right now will let you know if it works

  • Awesome that totally solved the issue of trying to have a looped cyclical menu, however, this appears to still be affecting the music the same way as before (instead of playing, the music starts repeatedly infinitely) will continue to try to get it to start the song once and then simply play it. Interesting note as this implies that the problem with the music was not actually due to the "For" statement as I previously theorized.

  • I think you've overcomplicated the menu logic, there isn't a need for a for loop or booleans to turn songs on and off. You didn't share any of the logic where you are playing the music but my guess if you have it set to play audio every tick when you need a trigger once.

  • Here is the full song selection menu as it stands now

    [img=

    ]

  • I forgot to include in snapshot but at bottom there is a command to set the global number to 0 if the songchoosebar is invisible, this makes it so it goes to 1 at the start of the menu appearing. (Thus beginning at Track/Song One)

  • I realized that despite the weird bug of the music not actually playing within the song menu (it basically just repeats over and over rapidly) it does however select the song and begins playing it correctly once the menu is exited;

    I mentioned before [before removing out of concern of relavence] but this all takes place within a pause menu that sets the timescale of the game to 0, that is probably the reason for the music not playing properly I'm assuming at this point.

    Regardless, my issue now is attempting to make it so that all music is essentially muted, which I hopefully can accomplish simply by just muting all songs while in the menu and unmuting them outside of the menu. Though I predict there may be issues implementing this if the timescale is in fact and continues to interfere.

    Thank you so much for your help though! As I mentioned above many of the seemingly obvious solutions seem to whiz right by me due to my newbie status of code knowledge, I really appreciate the assistance and will update again if the mute works or not.

  • No problem. As predicted you are trying to play the song every tick, you need 'trigger once' condition under the track = x events, so that when track variable is updated it plays the song once. At the moment it is just running continuously so restarting the music over and over, it won't be anything to do with timescale.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • omg thank you, my brain is almost jello from shooting in the dark lol, thank you, I had no idea there was a trigger once function

  • IT WORKED! thanks dude

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)