0 Favourites

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

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy 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: https://www.scirra.com/forum/viewtopic.php?f=147&t=150482&p=954835&hilit=dialog+tutorial#p954835

    so you might want to check that out.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,137
karshinkoff's avatar
karshinkoff
Unread hot topic
56 4,731
MPPlantOfficial's avatar
MPPlantOfficial
Unread hot topic
76 9,273
Pandadoor's avatar
Pandadoor