Random Dialogue/No Repeats

0 favourites
  • 13 posts
From the Asset Store
Template for a generic save / load system, fully documented in comments and video
  • I've hit a wall on this. I have random dialogue but atm it repeats. I want to have each line to only fire off once on a play through. I was determined to figure it out myself. I ask for help in IRC and while the advice was sound, I couldn't implement the ideas. I've tried and tried some more. Then I tried more after that. I can't figure it out. I need help.

    I'm including the whole .capx (it's a big file because of large images). It's a bit to wade through but the important parts are in the "Globals" event sheet under the "Touch" group. And the "Dialog" sheet. I only worked on the "Yes" option.

    dropbox.com/s/1npeolvwmxuej0l/Sbb2Help02.capx

    Any help is appreciated. Thank you.

  • If you choose to keep doing the dialogue in this manner (which I'm not sure is the greatest way for it) I guess the solution would be to remove the entry after using it, or setting it to 0 in the array. And set the text to the random array value if the array value is not 0 and else repeat the set text to random untill an array value is found that isn't 0.

  • That is exactly what I tried to do. I just couldn't figure out how to do it.

  • Keep all dialogues in an array. Install scirra.com/forum/plugin-pattern-gen-easter-egg_topic59168.html plug in. It creates random number in given range without repeat. And use that as an index to array of dialogues. I did something like what you are trying and this helped me.

  • Thank you, this looks like it might be what I need. Unfortunately, I don't understand how it works. I can't make sense of the example capx. Is there anything you can tell me about how I can use it?

  • I can't figure this out. I can't make shuffle work. I don't know what I'm doing.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Can someone please help me?

  • I cannot download your capx at the moment, but I will try to solve your problem. I will pretend your array is called DialogArray. To get the array to work, I would first set your array to a size of (number of dialogs you want, 2, 1) on the start of the layout. In the first dimension of the array, I will store whether or not this piece of dialog has already been used, and the second dimension will be used for the text itself. Create a global variable called NumberOfDialogsUsed (or whatever you want to call it) and leave it set to 0.

    I am assuming you have some variable which stores the location in the array that you want to display, and I will pretend it's called PickedDialog.

    When you want to pick a dialog:

    If NumberOfDialogsUsed < DialogArray.Width | PickedDialog = floor(random(DialogArray.Width))

           (subevent)

           While

           DialogArray.At(PickedDialog) = 1 | Add 1 to PickedDialog

                  

                  (subevent)

                  If PickedDialog > or = DialogArray.Width | Set PickedDialog = 0

           (subevent)

           (no conditions) | Add 1 to NumberOfDialogsUsed

                            | Set DialogArray.At(PickedDialog) = 1

    Now to display your text, you will find it at DialogArray.At(PickedDialog, 1)

    In this example, once you used up every dialog, nothing will happen when you want to display text. At this point if you would like to pick from all the dialogs again, you will have to set NumberOfDialogsUsed = 0, and loop through your array and set DialogArray.At(loopindex) = 0

  • Thank you for the help. I couldn't make this method work, however I did eventually figure out a way to do what I wanted. :)

  • Threw together a quick example.

    We iterate through an array and delete values as they are returned.

    dl.dropboxusercontent.com/u/139218609/examples/randomnorepeat.capx

    If deleting the values isn't a viable option then you might add to the array depth and use it to store whether or not a value on the x axis been accessed.

  • Noncentz705

    Great example. I have a question: how can I restart the array without restart the layout?

  • Once the array is emptied it's width becomes 0; we'll re-size the array to a width of 10, and re-populate the x axis with new values. Hope that helps, if you have any questions just ask.

    dl.dropboxusercontent.com/u/139218609/examples/randomnorepeat2.capx

  • Noncentz705

    Very good solution. I was looking for a randomization system without repetition and never knew how to use Array. This example was perfect. Many thanks for posting this solution.

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