Best way to add data to the first row of a table

tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
I know this is a simple question but that's what the forums are for, right? ;)

Now that I'm using tables extensively for a game I'm building, I'm finding some quirks with the first row data that's causing problems. If I have a blank table and I want to add data to the table by adding a row at the end each time, I have to do:

When TableRowCount(TableName)=1 and TableCellValue(TableName,1,1)=”” change table value for row 1; Otherwise, add row to table at end and change table value at end row.

Without the RowCount rule, if I just add a row at the end of a "blank" table, it adds it at row 2, not row 1, and I end up having a table with a blank row at the top which causes all sorts of problems for counting rows, etc.

Is this just a fact of life or am I missing something? I really wish that tables could have zero rows.

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • IsabelleKIsabelleK Member, Sous Chef Posts: 2,807
    I don't get it - do you want to add data to the first row of the table, or to add a row with data at the end?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Both. I want to always add data at the end of a table (in a new row) but if the table is blank, I want to add data to the first row. As it stands, if I create a new table and then add a row to the end of the table, it gets added to Row 2.

    Here's an illustration:

    *BEFORE*
    Table
    Row 1:

    Add row to end of table
    Change row 1, col 1 to "hello"

    *AFTER*
    Table
    Row 1:
    Row 2: "hello"

    What I want is for my table to start out blank and after adding a row, to have ONE row.

    *AFTER*
    Table
    Row 1: "hello"

    Maybe it's a pipe dream.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • IsabelleKIsabelleK Member, Sous Chef Posts: 2,807
    I have something similar in one of my games:
    First, I have Constrain behavior: game.TableRows to tableRowCount(game.Rotation).
    And a rule (after some actions):
    If (here are some attributes, but unimportant for this message):
    Change attribute: self.RowAdded to true
    Add row: Table: Rotation; Action: Add Row, At The End.
    Timer, after 0.1 seconds. Change attribute self.MyRow to game.TableRows

    And then I have some other unimportant rules, and then:

    Rule, if self.RowAdded is true
    Timer, every 0.0001 seconds. Change Table Value: Table: Rotation; Row: self.MyRow; Value: self.Rotation.

    That's all :)
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @TheMoonwalls I don't see how that addresses the issue of the first row being blank. In your example, I believe you'll still have a blank first row and then a second row (that was added to the end) with self.Rotation stored there.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited December 2012
    I think I know how to do this. Just have to test my idea. Post results in a few. Are all your tables text attributes?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @TheMoonwalls, don't get me wrong... I appreciate the suggestion! :)

    @FryingBaconStudio... mostly text: about 5 integer columns out of 500 columns.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @tatiang -- is there a reason why you couldn't delete the first row of the "blank" table immediately upon game startup? It doesn't seem to hurt anything to have a table with 0 rows and 1 column.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I think I ran into problems trying to add a row to a table with 0 rows and then change the data in that (first) row, but I'll check again. That was my preferred solution.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited December 2012
    Got tied up yesterday. I'll throw together the code this morning with my idea. How many tables are you using?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Thanks, @FryingBackStudios. I ended up using the same strategy in the game I'm building. Instead of deleting the first row, I just change it if it's empty.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.