Copy random rows from columns from original table into a new table?

fatpenguinfatpenguin Member Posts: 2
edited February 2018 in Working with GS (PC)


I've looked everywhere for an answer for this, I would be grateful if someone could help me.

I have a table made up of several columns, with each column containing multiple rows. Is there a set of rules/behaviours I can create to copy a random selection of rows from each of the columns into one giant column in a new table?

For context:

I want to create a game where I want the game to load a deck of cards with certain words (in table rows) on them, separated into topics (columns). The user selects what topics they want the words to come from. I then want the game to load a set of random words from the topics (aka columns) the user selected. The simplest way to do this in my head is to copy the rows from different columns from the first 'database table of words' into a temporary single column in a new table for use during one play session.

I hope this question makes sense? Any help would be greatly appreciated!

Best Answer

  • awesome_wellsawesome_wells Posts: 37
    Accepted Answer

    Hi @fatpenguin,

    One way you could do it is to create an actor with two attributes e.g. "Cell read contents" and "Cell write row number"

    Now, if your master table (Table 1) is 10 rows by 4 columns, and your temp table (Table 2) is 10 rows by 1 column for example:

    Create a loop that repeats until self.Cell Write row number is less than or equal to 10

    This loop contains:

    Change Attribute - self.Cell Read Contents to tableCellValue( game.Table 1 , self.Cell write row number ,random(1,4))

    Change Table Value :-
    Table:Table 2
    Row: self.Cell write row number
    Column: 1
    Value: self.Cell Read contents

    Change Attribute - self.Cell Write row number to self.Cell Write row number+1

    This loop will write a random column value (from 4) for each of the 10 rows of the master table in to your temp table.

    I'm working on Mac, I've attached an example of the steps above, but not sure if it will work ok for PC, but give it a try :smile:

    I hope that helps, and that I understood correctly!


Sign In or Register to comment.