Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

shuffle images from pool

edited June 2021 in OSWeb

Hi everybody,

I am planning a memory experiment in which subjects are presented with lists of words when each word should appear on a different background - a picture of a forest or a picture of a sea.

I uploaded the images to the pool but I can not pull them from the pool and create a randomization between them. When I run the experiment I get no error but the words appear on a black background and not on the background of the images.

I do not know the software well and I mostly do not know JS codes.

I used these lines:


function randomArrayShuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var backround=["sea", "forest", "sea", "forest", "sea", "forest","sea", "forest", "sea", "forest", "sea", "forest", "sea", "forest", "sea", "forest"];
randomArrayShuffle(backround);
backround.pop();


Thank you.

Zohar

Comments

  • Hi Zohar,

    I am not an expert on JS, but to see whether there actually is an error message, you can check the console of the browser in which you are test running your code. Do you know how to access it?

    In any case, assuming that there is indeed nothing wrong with your script, it would mean that not the randomization is flawed but the drawing part. How did you implement that? You can upload your experiment if you wish (incl. some of the images).

    Eduard

    Ps. I believe in your code, you can't just pop the background, you need to capture it in a variable of vars

    For example something like this:

    vars.background = backround.pop()

    Buy Me A Coffee

  • FabFab
    edited August 2021

    Hi @zohar ,

    Your code works but you're probably not passing the information to the picture object on your sketchpad. But I'd modify the end:

    function randomArrayShuffle(array) {
    var currentIndex = array.length, temporaryValue, randomIndex;
    while (0 !== currentIndex) {
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
    }
    return array;
    }
    var backround=["sea", "forest", "sea", "forest", "sea", "forest","sea", "forest", "sea", "forest", "sea", "forest", "sea", "forest", "sea", "forest"];
    vars.newarray = randomArrayShuffle(backround);
    console.log(newarray)
    

    This line stores the shuffled array into a variable you'll be able to access from the trial sequence:

    vars.newarray = randomArrayShuffle(backround);
    

    If you add the following line at the end of your script, you'll see the shuffled list in the console to check that it is indeed shuffled:

    console.log(newarray)
    

    I think the issue may be with the structure of your task or the lack of attribution of the content of the shuffled array to a variable that your task actually uses to retrieve the picture in the pool.

    A couple of clarifications first...

    (1) I'm going to assume that you want to randomize the order of the background pictures independently of the randomization of the trials in your loop. If you weren't, then I'd question the rationale for using the code at all (since you'd just have to set the order of the loop to "random").

    (2) Just to be on same page, let's clarify that that code must be executed ahead of a block of trials (since you have 10 elements in your background array, I'm assuming that your loop contains 10 trials). Your use of the the pop function in that code makes me think you're actually truing to use the code on every trial...

    With these out of the way, let's address the key issue. I think that the reason your screen remains black is because shuffling an array does nothing else than shuffling an array. That is, it does not show pictures. To show pictures, you'd have to have a sketchpad in your trial sequence with an actual picture object. Then the whole issue becomes what picture file you set that object to display on every trial. You'd want that information to be pulled from a column in your loop.

    So I think that what you're missing is the bit where you scan through the shuffled array, as the loop runs, to tell the task to use and nth element of the array for the nth trial in the loop. That's where you'd use the vars.newarray and select the elements one by one (taking the 1st + ".jpg" in the 1st trial, the 2nd + ".jpg" for the 2nd trial etc.).

    Have a look at the solution published here. I think it should help.

    Note that in that solution, I do not alter the shuffled array, I just navigate through it as trials go. So, I'm not using the pop function as you do in your code (that is destructive as is eliminates the last element of the array). The fact that you have it in that code makes me think that you've placed the code in the trial sequence instead of before the loop. It would make little sense to build the array and eliminate the last element before running the loop. And it makes little sense to recreate a new shuffled array on every trial to just use the last element with the pop function. So, in a nutshell, the shuffling must be done once and before the loop. No "pop" at that stage. Then, in the trial sequence, you can use the pop function to select the last element of the array (so that trial by trial, your array will shrink to nothing). In the example above, I have not used this destructive method. Instead, I leave the array intact and count the trials to go pick the elements in turn.

    Good luck!

    Fabrice.


    _____________________________________________________________________________________

    If you found my reply helpful and wish to invite me to a coffee, you can do so here 😉: https://www.buymeacoffee.com/psyfab

    Buy Me A Coffee

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games