Howdy, Stranger!

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

Supported by

Pseudorandomization

Hello,

I createt a list and I want to be sure, that the same word (e.g. ROT) does not appear several times on the trot , so I want to check, if the current stimulus is the same as the stimulus before; and how can I avoid this?

I work with inline_javascript :)


Thanks!


Comments

  • Hi @Lisa_99,

    Since you work with inline_Javascript, I'm gonna assume that you intend to run your experiment through OSWeb within a browser.

    Just for your information, if you were not, you could simply use the "constrain maxrep" command in the loop's script. However, since this method is not supported in OSWeb.

    I put together a basic example simply presenting 10 words, one per second, and implementing code that ensures that the same word is not presented on succesive trials.

    The logic is the following:

    1) Assuming that the information about the stimuli is contained in a csv file (present in the pool), we use some Javascript before the loop to read the CSV file, shuffle its rows while making sure that the same word (contained in the word column) is not repeated on consecutive trials.

    Code (note that I added several lines writing to the browser's console, so that you can follow what's going on as the task runs; just make sure to open your browser's console to see it):

    console.log("πŸš€ Starting CSV Processing and Shuffling...");
    
    // Ensure OSWeb's csvParse function is available
    if (typeof csvParse !== "function") {
    console.error("❌ csvParse function is not available. OSWeb may not be running correctly.");
    }
    
    // Load and parse the CSV file using OpenSesame's file pool
    try {
    console.log("πŸ“‚ Trying to load 'stimuli.csv' from file pool...");
    
    // Correct way to parse CSV in OSWeb
    const trials = csvParse(pool['stimuli.csv'].data, { columns: true });
    
    console.log("βœ… Successfully loaded and parsed CSV.");
    console.log("πŸ“„ Parsed Trials from CSV:", trials);
    
    // Function to shuffle trials ensuring no consecutive repetition of the "word" field
    function shuffleNoRepeat(trialList) {
    console.log("🎲 Starting shuffle process...");
    let shuffled = [];
    let availableTrials = [...trialList]; // Copy the list to avoid modifying original
    
    while (availableTrials.length > 0) {
    let possibleChoices = availableTrials.filter(trial =>
    shuffled.length === 0 || trial.word !== shuffled[shuffled.length - 1].word
    );
    
    console.log("πŸ‘‰ Possible choices for next trial:", possibleChoices);
    
    if (possibleChoices.length === 0) {
    console.warn("⚠️ Warning: Unable to prevent consecutive duplicates. Restarting shuffle...");
    return shuffleNoRepeat([...trialList]); // Restart shuffle if stuck
    }
    
    let choiceIndex = Math.floor(Math.random() * possibleChoices.length);
    let chosenTrial = possibleChoices[choiceIndex];
    
    shuffled.push(chosenTrial);
    availableTrials.splice(availableTrials.indexOf(chosenTrial), 1);
    }
    
    console.log("βœ… Shuffled Trials (no consecutive words):", shuffled);
    return shuffled;
    }
    
    let shuffledTrials = shuffleNoRepeat(trials); // Shuffle trials while avoiding consecutive repeats
    
    // Store shuffled trials as a JSON string (OSWeb does not support arrays directly)
    vars.shuffledTrials = JSON.stringify(shuffledTrials);
    vars.trialIndex = 0; // Initialize trial counter
    
    console.log("πŸŽ‰ Successfully stored shuffled trials in OSWeb variables.");
    
    } catch (error) {
    console.error("🚨 Error processing the CSV file. Ensure it is in the file pool.", error);
    }
    

    2) we make sure that the loop is set the appropriate number of times (i.e., the same number of times as the words). Let's say we have 10 words (so 10 trials). You could either use one cycle and have 10 rows, or you could have a single row and set the number of cycles to 10 (which is what I have done).

    (3) Inside the sequence, at the beginning of the trial we insert some inline_Javascript and insert some code in the prepare phase (not the run phase) to populate the trial with information from the shuffled array we previously stored.

    Code:

    console.log("πŸ”„ Fetching next trial...");
    
    // Retrieve and parse shuffled trials (convert JSON string back to an array)
    if (typeof vars.shuffledTrials === "string") {
    console.log("πŸ“ Converting stored JSON string to an array...");
    vars.shuffledTrials = JSON.parse(vars.shuffledTrials);
    }
    
    // Ensure the trial index is within bounds
    if (vars.trialIndex < vars.shuffledTrials.length) {
    let currentTrial = vars.shuffledTrials[vars.trialIndex];
    
    console.log(`🎬 Presenting Trial ${vars.trialIndex + 1} of ${vars.shuffledTrials.length}:`, currentTrial);
    
    // Assign values to OpenSesame variables
    vars.word = currentTrial.word;
    vars.condition = currentTrial.condition;
    vars.color = currentTrial.color;
    
    console.log("πŸ“Œ Assigned values -> Word:", vars.word, "| Condition:", vars.condition, "| Color:", vars.color);
    
    // Increment trial index for the next trial
    vars.trialIndex++;
    } else {
    console.error("❌ Trial index out of bounds. Check the number of trials in your CSV file.");
    }
    


    You should be able to adapt this code to you own experiment.

    Hope this helps.

    Best,

    Fabrice.

    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