Problem with add/remove data from tables

NYPNYP Member Posts: 12
Hi,

I have set up a table that i wish to remove rows from during the game. i can call data from the table fine, but my remove data behaviour doesn't seem to work at all. Have i missed something in setting up the tables or is there something about the use of the behaviour that i am missing?

Thanks

Comments

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited January 2014
    How have you got it setup at the moment..?

    Here's the provided text about the add/remove behaviour.

    Add Remove Row (Action)

    This behavior allows the user to select a table, and add or remove rows from the selected table. "Action:" can be either Add Row/Remove Row, At Beginning/At End/At Index, if At Index is selected, then the expression field will be displayed which will then allow the user to select which index to use. If a row is add, it will shift everything above up by one at the location. If a row is removed, it will shift everything above down by one location. If the table data needs to be persisted, it will need to be saved by the save table behavior above.

  • NYPNYP Member Posts: 12
    Hi Stormy Studio,

    Basically i have a set-up behaviour where i spawn actors into different zones (6 in total) selected at random. I want there to be no two actors in the same zone, so i have made a table of one column and 6 rows, containing the numbers of 1-6. When a number is selected by taking a value from the table i want to remove the selected row (remove row At Index) from the table, thereby making impossible for that zone to then be selected again. Basically it's a workaround for the lack of Arrays. As I say the theory works but the table doesn't seem to want to be editable.



  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited January 2014
    Hmm.. like you say the theory works..

    Not sure what rules you've put in place but I'd do it as follows (this is being written on the fly so I'm sure it could be simpler):

    Make a table,
    1 column, 6 rows, of type integer, type numbers 1 through to 6 in each cell.

    Make some game attributes:
    Make an integer game attribute 'game.spawn_actor' = 1
    Make an integer game attribute 'game.row_number' = 0
    Make an integer game attribute 'game.number_spawned' = 0
    Make an integer game attribute 'game.max_spawn' = 6

    Create an actor which controls the spawning.
    Add a rule
    If game.spawn_actor = 1
    If 'game.number_spawned' < 'game.max_spawn'
    change attribute 'game.row_number' to 'random(1,tableRowCount(table_name))'
    spawn your actor.
    change attribute 'game.number_spawned' to 'game.number_spawned'+ 1
    change attribute 'game.spawn_actor' = 0

    In the actor that is to be spawned,
    have a self attribute. called self.zone_number
    add a change attribute behavior: (does'nt need to be inside a rule as it can run as soon as its spawned)

    change attribute 'self_zone_number' to 'tableCellValue(table_name,game.row_number,1)'. THIS IS TELLING IT TO LOOK AT THE TABLE AND SAVE THE NUMBER IN THAT ROWS CELL TO ITS OWN ATTRIBUTE.

    Add change attribute rules to change its position to the relevant coordinates for that self.zone_number. (you could have it take the numbers from a separate column of the same table, before the row is deleted, if you wanted to easily store the x and y values in the table.. but do what seems best.).

    then add the 'remove rows behavior', and for the index number put in the game.row_number.

    Then to trigger the next spawn add one last change attribute.
    change attribute 'game.spawn_actor' to 1


    ...
    well thats my head fried... I have'nt tested the above but think it should work correctly.


  • NYPNYP Member Posts: 12
    Thanks, i'll give it a go this afternoon and let you know how i get on. Appreciate the help!
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    No probs...

    Good luck.
  • NYPNYP Member Posts: 12
    Hi again,

    I've had another go and again the trouble still seems to be with my use of the add/remove behaviour.

    To test this i did the following:

    Created a table ("Table 1") of 6 rows each containing the equivalent integer value(1-6)

    https://www.dropbox.com/s/2k0x3jzzk3c5xre/Screenshot 2014-01-23 11.39.38.png

    Then i created one actor with one behaviour, add/remove the first row of the table:

    https://www.dropbox.com/s/1x2ab89kmp9t9t0/Screenshot 2014-01-23 11.38.28.png

    When i preview the scene and return to the table in the editor, the table is identical to its initial state, whereas it should now only have 5 rows containing the numbers (2-6)

    So this seems to be saying that the problem is with editing the table, right?

    Any ideas where i'm going wrong?

    Thanks!
  • slowcutslowcut Member, PRO Posts: 164
    @NYP the add/remove row behavior only works in runtime, there is no effect to the tables in the Editor, so you will always have every row in your original table when you quit preview and go back to the editor
  • NYPNYP Member Posts: 12
    @slowcut I thought the add/remove was a permanent change of state which is why you needed to copy the data into a new table if you wanted to revert back? I must have got that wrong, thanks for clearing it up
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    its permanent... in an actual game... but not when developing...
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    This will help you see what your tables are doing... :-)

    http://stormystudio.com/game_templates/GS_table_izer.html
  • NYPNYP Member Posts: 12
    @StormyStudio Thanks! I built a testing model from scratch and finally found that the problem was (obviously) with how I was referencing the row index! Problem solved, thanks for the help
Sign In or Register to comment.