Random placement of quiz answers, using the expression editor

scottwoodscottwood Member, PRO Posts: 68

I’m trying to randomise the placement of the answer actors in a quiz. With four options there are only 24 permutations (n factorial), so I’m using a table with predefined permutations on each row. I then use a random function to set the row selection as a game variable. This seems to work well, but there must be a better way to use when the number of options are increased, just using the expression editor.

Comments

  • JapsterJapster Member Posts: 672
    edited January 2018

    @scottwood said:
    I’m trying to randomise the placement of the answer actors in a quiz. With four options there are only 24 permutations (n factorial), so I’m using a table with predefined permutations on each row. I then use a random function to set the row selection as a game variable. This seems to work well, but there must be a better way to use when the number of options are increased, just using the expression editor.

    @scottwood - I think myself and others have used a simple solution where you randomly copy a start table into another, or even copy a row into memory (temp attributes), delete that row, and randomly re-insert the data in to a freshly created row - this works really well, to juggle placements around.

    Other may have different methods, but here's one, eg:-

    In my example it's slightly different - I add a row randomly to my table (it's always 16 rows), hence I add a row randomly, then copy the data from the now temporarily pushed down row 16 (row 17) for an easy juggle logic. if you run this logic more times than your number of items (or even less in fairness!), you'll have a pretty random assortment of data)

    Note:- Loop Over Table can be used, with increased iterations per loop step, to achieve this fairly instantly, but for my puzzle game, I wanted a visual 'swapping around' effect (images are constrained to each actor based on the current value in their allocated row... :smile:

    Hope that helps!

    ...again, alternatively, you can do the same sort of thing across 2 tables, using a temporary 'donor' table, select a random row between 1 and rowCount(Your_Table), add it to the target (initially empty) table, and delete the row from the donor, repeat until your 'RowCount' returned value for the donor table is 1, and you'll have a randomly sorted target table!... :smile:

  • scottwoodscottwood Member, PRO Posts: 68

    Thanks, I’ll certainly give this a try. Shame there’s no function for this type of thing.

  • JapsterJapster Member Posts: 672
    edited January 2018

    @scottwood said:
    Thanks, I’ll certainly give this a try. Shame there’s no function for this type of thing.

    @scottwood - To be fair, there are probably easier ways, but once this routine is written, it'll serve you well... :smile:

    The problem with randomly generating positions, is that unlike completely random, none-unique numbers (where you don't care about dupes), you're basically selecting from a pool of candidate positions to allocate them all, and only once, so I think in fairness there's no way a single function or expression would perform that (without being massively convoluted, in the expression editor!)

    You can get a really quick randomizing by just duplicating the swap behaviours group, ie. run 3 times every pass:-

    Where I've simply grouped the 'juggle 1 row' behaviours, and pasted them again... :)

  • ArmellineArmelline Member, PRO Posts: 5,331
    edited January 2018

    I've always favoured populating a string with a series of numbers and removing them as they're use.

    01,02,03,04,05 etc.

    Then you can remove individual numbers to remove them from the available pool. Adding new numbers is equally easy. Less overhead than extra tables, and more flexibility.

  • JapsterJapster Member Posts: 672

    @Armelline said:
    I've always favoured populating a string with a series of numbers and removing them as they're use.

    01,02,03,04,05 etc.

    Then you can remove individual numbers to remove them from the available pool. Adding new numbers is equally easy. Less overhead than extra tables, and more flexibility.

    Boom! - and there it is - you gotta love @Armelline - his solutions are always streamlined... :)

    My trouble is I'm fixated on tables! :smiley: ...Although I find using them helps me generally keep from having to unlock actors all over the place, so I'm kind of stuck in my ways.. :smile:

  • ArmellineArmelline Member, PRO Posts: 5,331

    @Japster said:
    My trouble is I'm fixated on tables! :smiley: ...Although I find using them helps me generally keep from having to unlock actors all over the place, so I'm kind of stuck in my ways.. :smile:

    Tables are an entirely valid choice :D But unlocked actors... shudders :D

This discussion has been closed.