Trying to link to a pool of questions

I am trying to generate a type of quiz that when you click next it randomly pulls from a pool of questions. When I bracket the questions it skips right to the text of the first listed one., in this case #1 bla bla bla.


<p>You answered the question correctly. Good job.</p>
<p>Ready? [[Go]](ready).</p>
[[ready]]:
    var randomnumber = function rng(min, max) {
      return Math.floor(Math.random() * (max - min) + min);
    }

    set ("Nextques", randomnumber(1,3));

Let's move on to number {Nextques}.


[[Next]]({Nextques})


[[1]]:
@clear
bla bla bla

[[2]]:
@clear
yo yo yo

[[3]]:
@clear
yes yes yes

Should

set ("Nextques", randomnumber(1,3));

be

squiffy.set("Nextques", randomnumber(1,3));

?


It works fine when I use it in my game for money, like this below but I can't get it to work to pull random questions.

<p>You have survived that encounter. Good job. You are alive, for now.</p>
<p>You search the dead man and find some [[cash]](deadmoney1).</p>
[[deadmoney1]]:
    var randomnumber = function rng(min, max) {
      return Math.floor(Math.random() * (max - min) + min);
    }

    set ("Deadcash1", randomnumber(2000,3000));
    set ("money", get("money") + get("Deadcash1"));

You found {Deadcash1} bucks. Hmmm, maybe it pays to be bad.<br>
<b>Money = {money}</b><br>
[[Continue]](moneytime)

I had to add the first two lines so it would start me at "You answered the question correctly."


I changed up your Next section, adding a passage which uses JS to find the variable:

[[Next]]:
    squiffy.story.go(squiffy.get('Nextques'));

This works for me:

@start thisPart
[[thisPart]]:
<p>You answered the question correctly. Good job.</p>
<p>Ready? [[Go]](ready).</p>
[[ready]]:
    var randomnumber = function rng(min, max) {
      return Math.floor(Math.random() * max) + min;
    }

    set ("Nextques", randomnumber(1,3));

Let's move on to number {Nextques}.


[[Next]]

[[Next]]:
    squiffy.story.go(squiffy.get('Nextques'));


[[1]]:
@clear
bla bla bla

[[2]]:
@clear
yo yo yo

[[3]]:
@clear
yes yes yes

Oh, yeah...

I also changed your random integer function because it was only choosing between 1 and 2 with max-min in there.

    var randomnumber = function rng(min, max) {
      return Math.floor(Math.random() * max) + min;
    }

K.V. This is awesome. Thank you. On my phone now but will try when I get home.

And as far as the random integer function, that's weird. I use it to give a value, in the example I used it was money, and it gives random between the two values. Helps if a player takes the exact same route, they can still have a different outcome with a second playthrough. But I will surely check out your work as it always proves amazing.

I will let you know the final verdict when I get home. 👍🏽


Well, thank you, kindly (but you're overrating me, hehehe).

return Math.floor(Math.random() * max) + min;

I got that from here:
https://www.w3schools.com/js/js_random.asp

Looking at the last few examples now, I can't tell you the difference between these two:

return Math.floor(Math.random() * max) + min;
return Math.floor(Math.random() * (max - min + 1) ) + min;

Very nice, worked great for me. Adding the @start with a link help make it start where it was supposed to. Without it it kept going straight to the first question. And I changed the integer as well. It would only give me questions 1 and 2.

Thank you very much


Glad to help!

Every time you ask about something, we both learn something! It's a win-win!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums