How do I use an if statement within a while loop?

0 favourites
  • 2 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Hi guys.

    I'm rewriting a game so that dialogue is done via a while loop. I'm not of high enough reputation to link anything yet, so I'm going to describe what I have as clearly as I can. Hopefully you will be able to help!

    There is a global variable called dialog. As long as this variable is less than or equal to 5 (the number of dialogs a player will click through when talking to a particular NPC), while (dialog <= 5) is true and still running. Now inside of the while loop, if the player clicks the 'next dialog' button, the next dialog should show up and the dialog variable should increment by 1. This does not go as planned, however. When I try starting the game, the screen stays black and it hangs at a percent. I'm guessing this is because the while loop never has a chance to stop itself.

    I don't know how to fix this. I've tried all day with no luck. Any takers? That is literally all I have by the way. There aren't any other variables or things to worry about. I figured I'd narrow the issue down to make it work. But...I'm stuck.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • agaman - Does sound like you have an infinite loop there...

    You don't really need the while loop. An Event sheet automatically loops already. At the start of layout, just show the first dialog. Then have an event for when the player clicks the next button to increment the global variable and display the next dialog.

    Kyatric just did a tutorial on making a dialog system last month:

    so you might want to check that out.

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