Separating training rounds

#1

Hello,

In my project, first, there will be training rounds (approximately 20 min) and after the announcement, subjects will start the final round where their payoff will be calculated.
I am not quite sure how can I manage it with Forio. The only possibility that I can think of is the following:

I can have a timer that is set to 20 min. After 20 min, I can have a warning saying that it is the final round now and restart button can disappear. But I do not want to interrupt the subjects in the middle of a round. Could you please guide me on this subject? Any suggestions?

Also, is it possible to make a button useless after a certain number of clicks?

Thank you

0 Likes

#2

Hi Busra,

We are looking into the scenario you have provided.
We’ll let you know based on our investigation.

Regards,
Geromel

0 Likes

#3

Hi Busra,

re: make a button useless after a certain number of click.

It depends on your use-case. A quick-and-dirty version is:

<script>
  var timesButtonClicked = 0;
 $('#mybuttonid').on('click', function(evt) {
    timesButtonClicked++;
    if (timesButtonClicked > 3) {
         $(evt.target).prop('disabled', true);
    }
 });
</script>

If the user refreshes the page he’ll be able to click on this again. An alternative approach involves using a model variable to decide when to disable it.

<button data-f-disabled="somebooleanModelVariable" id="mybuttonid">Click Me</button>

You’ll need to set/increment a model counter variable somewhere else.

re timer

Timers are very tricky to work with in Javascript. A naive approach would be to do something like the following:

<button id="timerBtn">Start Timer</button>
<div data-f-show-if="isTimeOver">Time over</div>
<script>
$('#timerBtn').on('click', function () {
   Flow.channel.publish('StartTime', Date.now()); //Assumes "StartTime" is a variable in your vensim model
});
setInterval(function () {
  Flow.channel.publish('currentTime', Date.now()); //Updates "currentTime" variable in your model every minute
}, 60 * 1000);
</script>

Within your model isTimeOver would return true only if “CurrentTime - StartTime > 20mins && Time > 3” or something like that.

0 Likes

#4

Hello,

I decided that number of clicks will not work in my context so I need to go with timer.

As I explained before, participants play the same game over and over again but first 20 minutes will be training and then there will be a last round. So, after 20 minutes, if they are in the middle of a run, I want to give them enough time to finish that round and restart the game for the last time.

I was thinking of having a timer starting from the first time they click on the simulate button.
The other alternative could be the following: I know more or less when they will start so if it is easier and less trickier, I can use the calendar time: like making an announcement on November 2 at 16:30.

In the context of timer, which one would you recommend? Other suggestions are also welcome.

Thank you

0 Likes

#5

Using absolute time will be a lot easier, so would recommend that. You need to

  1. Convert the desired time to “epoch time” (it’ll be of the form 1509637747 - you can find a lot of online converters to do this).
  2. In javascript, have a simple loop which checks if it’s time every minute or so and if it is, sets a model variable. Something like (rough untested code)
var timer;
Flow.channel.subscribe('timeUp', function (value) {
  
   if (value === 1) {
      //variable has already been set
      clearInterval(timer)
   } else {
        timer = setInterval(function () {
            var currentTime = Date.now();
            var targetTime = 1509637747;
            if (currentTime >= targetTime) Flow.channel.publish('timeUp', 1)
        }, 60000)
   }
});

The rest of the UI can be conditionally shown based on the timeUp with show-if and hide-if etc. You’ll need to double/triple check the timer logic and make sure the code for turning it off works fine, otherwise you’ll end up hammering the server and making gameplay a lot slower for your players.

You’ll need to update the targetTime in the code for each class of course. Let us know if you have questions.

-Naren

0 Likes