Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make the scene say something different each time? #68

Closed
Kalaborative opened this issue Jul 22, 2017 · 4 comments
Closed

How to make the scene say something different each time? #68

Kalaborative opened this issue Jul 22, 2017 · 4 comments
Labels

Comments

@Kalaborative
Copy link

Here is my code (using JavaScript and Jinja templating):

var myOffers = [{% for o in offers %}"{{ o }}",{% endfor %}];
var rand = myOffers[Math.floor(Math.random() * myOffers.length)];
theater
  .addScene('jjbot:' + rand, 900)
  .addScene('jjbot:')
  })

Basically every time an element is clicked, it runs theater.play(). The problem is, I would like it, if clicked again, to say something different (i.e. a different string in rand). I've tried doing theater.replay() but it only keeps displaying the same text. Is there a way to do this? Thanks!

@zhouzi
Copy link
Owner

zhouzi commented Jul 23, 2017

You could create the whole scenario once by adding each offers in a random order, something like:

// offers = list of strings
// random = function that returns a random int between min and max

while (offers.length) {
  var randomIndex = random(0, offers.length);
  var randomOffer = offers.splice(randomIndex, 1);
  theater.addScene('jjbot:' + randomOffer);
}

// Add a replay scene to loop over the scenario
// when all ofers have been written
theater.addScene(theater.replay);

And then, you could stop the scenario after each scene and wait for the user to click the element to play the next scene.

Let me know if that works for you.

@Kalaborative
Copy link
Author

@zhouzi thanks for your help on this!

I'm stuck on the while loop part. Is there any way to break out of the loop? The page just loads indefinitely for me.

@zhouzi
Copy link
Owner

zhouzi commented Jul 24, 2017

I made a jsfiddle with comments: jsfiddle.net/2bu4h9v5. It should clear things up 👍

@Kalaborative
Copy link
Author

This definitely helps.
Thank you so much for that clarity. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants