GameSalad

Howdy, Stranger!

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

Need help: Spawn actor and save all new spawned actor position (table?) how to

DarkpaxDarkpax Posts: 22Member
edited March 2013 in Working with GS (Mac)
Hey everybody I need help my idea is actor 1 spawns all 3 seconds an actor 2. The actor 2 spawns in random positions. My question is, how I save actor 2 position to table or anything ? I mean actor 2 spawns all3 seconds in another position and all positions should save. I need all positions to move to it with actor 3 in example , thanks for help

Comments

  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    I can't say I really understand all that you wrote, but this should get you started:

    Create a game attribute called game.spawnOrder (integer).

    Actor 1 needs to have Change Attribute game.spawnOrder to game.spawnOrder+1 immediately before the Spawn Actor behavior.

    Actor 2 needs to have a self attribute called self.spawnOrder (integer). At the top of the actor's rule list, have Change Attribute self.spawnOrder to game.spawnOrder.

    What that does is to increase game.spawnOrder by one each time Actor 2 is spawned and then Actor 2 assigns itself with that number. You can then use each Actor 2's self.spawnOrder to keep track of its position as follows:

    Change Table Value
    Table: [tableName]
    row: self.spawnOrder
    column: 1 value: self.position.X
    column: 2 value: self.position.Y

    Save Table [tableName]

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

  • DarkpaxDarkpax Posts: 22Member
    edited March 2013
    hey tatiang thanks for ur help, my english isnt so good. i ll try to do what u say.

    short example what i mean:

    actor 1 spawns actors 2.
    actor 3 should move to all actors 2 and destroy it (attribute pack +1)
    actor 3 move back to farm and for all packs i become money. 1= 100 2=100*2 or so...
    after become money actor 3 should move to another actor 2 and so on.
    and this should go automatic.

    look command and conquer for example with erz mining (red alert 1)

    thanks for every help have a nice day
  • DarkpaxDarkpax Posts: 22Member
    edited March 2013
    hey tatiang i have make ur example work , how can i move now with actor 3 to actors 2 position that was saved on table.

    my stuff to move actor 3 doesnt work with more actors (actor 2) .
    i make:

    rule: game.spawnorder greater than 0,0
    do:
    timer every 1 seconds
    do:
    move to
    position:
    for X:table cell value(table name,1,1)
    for Y:table cell value(table name,1,2)


    table is new for me.

    thanks

  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    Darkpax said:

    rule: game.spawnorder greater than 0,0
    do:
    Log Debugging Statement "RunRule"
    timer every 1 seconds
    do:
    Log Debugging Statement "RunTimer"
    move to
    position:
    for X:table cell value(table name,1,1)
    for Y:table cell value(table name,1,2)

    What happens when you run that rule? Does the actor move to the new position? Does it move at all? What happens if you add the behaviors in bold above and open the Debugger window? Do you see "RunRule" and "RunTimer" statements?

    I would use Interpolate instead of Move To, but your rule should still work with Move To.

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

  • DarkpaxDarkpax Posts: 22Member
    edited March 2013
    hey @tatiang this shows in debugger:
    Log(Actor: name): runrule
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer
    Log(Actor: name): runtimer

    endless ....
    actor move to only one actor 2 most the first or second one .
    to test i have make more actor 1 and all move to the first of all spawned actor 2

    the actor 2 know what coordinates it has

    but i make example too: display text:tablecellvalue(table name,1,1)this shows all time the same coordinate that the first actor 2 has spawn to(only on refresh another position )

    how can i move to the other of that .

    what do u mean with add the behaviors in bold above

    thanks a lot
  • DarkpaxDarkpax Posts: 22Member
    @tatiang hey can u help me.
    i make: display text:tablecellvalue(table name,1,1)
    this shows all time the same coordinate that the first actor 2 has spawn to
    (only on refresh another position )
    how can i add the right coordinates from every actor (actor 2)
  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    You can change (and save) the position of each actor to a different row and then use tableCellValue(tableName,1,1) and tableCellValue(tableName,2,1) etc. in your DisplayText behavior.

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

  • DarkpaxDarkpax Posts: 22Member
    @tatiang but how can i save a new row, i have all 2 seconds a new actor (actor 2) that spawns :/
  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    When you spawn a new actor, create a new table row within that actor

    Spawned actor
    Add New Row [at end]
    Change Attribute self.myRow to tableRowCount(tableName)

    Then use self.myRow as the table row for all of your Change Table Value behaviors.

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

  • DarkpaxDarkpax Posts: 22Member
    hey thank u @tatiang this help me to set actor spawn position =) now the question is how can i move to all this positions with one actor. all that rows are saved and i ll move to one of them , collide with this actor should delete the exactly row .

    example spawner spawns 3 actors (row count should now be 3) moveable actor move to one of this 3 (in same time it spawns more actors and new rows...)
    movable actor collides with actor with row 2 in the table. now i would delete actor 2 and row 2 in table, to delete this positions .row count -1. a counter in example would go up +1
    than movable actor move to an other actor with row 1 in example , and it should do the same. delete actor 1 and remove row 1 row count -1 .

    but i dont know how this is the best ... thanks i learn from u very well
  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    You're welcome. Okay, I think I understand. You want sort of a waypoint system where the actor moves from position to position and each actor at that position is deleted along with its table data.

    actor 2
    When actor collides with [actor name]
    .....Remove Row [at index: self.myRow]
    Destroy Actor

    Is the main actor going from actor to actor randomly or in the order that they were spawned? If it's in order, then you're right... you would change game.row to game.row-1 before the Destroy Actor behavior above.

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

  • CodeMonkeyCodeMonkey Posts: 1,803Head Chef, Member, PRO
    Remember, all spawned actors with an ID larger than the one that is about to be removed, needs to decrement its own ID, otherwise its self.myRow will no longer be associated with the correct row in the table.

    e.g. spawn 3 actors with IDs 1,2,3 and their rows in the table are 1,2 and 3 respectively.
    #2 gets destroyed and row 2 is removed. If you don't adjust #3's ID, then when it tried to delete row 3, that row will not exist in the table.
  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    Good point, @CodeMonkey.

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

  • DarkpaxDarkpax Posts: 22Member
    edited April 2013
    Thank u @tatiang and thanks @codemonkey, how can I automatically adjust the iD´s.

    I hasn t implement the move to spawned actors jet. I don t know how to move the actor to an self.myrow from an other actor.

    I think the movable actor need automatically all positions from all spawned actors.
    For now, its okay when the movable actor move randomly to the spawned one.

    i has test this idea for move....

    move to
    x: table cell value(name),random(1,self.myrow),1
    y: table cell value(name),random(1,self.myrow),2
    but when i test that and the movable actor spawn from my house the game stop working. i have a seconds timer and that stopp and flare

    Thanks.

    Greetings from Germany
  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    self.myRow is holding the row number that holds each actor's position. You're trying to pick a random number between 1 and that actor's row, which doesn't make sense. If you need to pick a random number, use random(1,tableRowCount(tableName)) instead.

    Also, put random expressions outside of the tableCellValue expression like this:

    Change Attribute self.randomRow to random(1,tableRowCount(tableName))
    Move To [x: tableCellValue(tableName,self.randomRow,1]
    Move To [y: tableCellValue(tableName,self.randomRow,2]

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

  • DarkpaxDarkpax Posts: 22Member
    nice, I get closer to the target i want to make =)
  • DarkpaxDarkpax Posts: 22Member
    edited April 2013
    After i finished an example game file for:

    Actor move to random spawned actor

    I upload the file for other one.

    Think I'm not alone with this.

    @tatiang
    how can i adjust all rows after remove a row
    sorry many wonder ...
  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    When you remove a row, the other rows automatically move up.

    So if you have these rows:
    A
    B
    C
    D
    E

    And you delete row 4 ("D"), you end up with this:
    A
    B
    C
    E

    Is that what you mean?

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

  • DarkpaxDarkpax Posts: 22Member
    1,2,3,4 rows
    2 remove 3 and4 must adjust but how to do
    Thank u. The movable works okay :)
  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    Darkpax said:

    1,2,3,4 rows
    2 remove 3 and4 must adjust but how to do
    Thank u. The movable works okay :)

    Sorry, I don't understand.

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

  • DarkpaxDarkpax Posts: 22Member
    Sorry i mean i have 4 rows , Row 2 was deleted / removed.than code monkey say the other rows over row 2 must adjust , 3 to 2 and 4 to 3 in example. How I make this .
  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    edited April 2013
    He's not saying to change the table at all. He's just saying that if your actor is getting its data from row 3, when row 2 is deleted the actor must then reference row 2 instead.

    So when you delete a table row, you'll need to change an attribute that each actor uses for its row value.

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

  • DarkpaxDarkpax Posts: 22Member
    thank u @tatiang. how i make this.

    this is what i make now(funktion only by one spawned actor):

    In the move actor a self random row integer.
    in rule i make change attribute. self random row to random(1,tableRowCount(game.table)-1)

    in spawned actor i make
    add row at end
    change attribute game.tablerowcount to game.tablerowcount +1
    change attribute self.myrow to game.tablerowcount

    change table value row: self.myrow
    column 1 self.position X
    column 2 self.position Y

    save table

    rule actor collides with actor of type (name)

    add/remove row
    remove row at index self.myrow

    change attribute game.tablerowcount to game.tablerowcount -1

    destroy actor
  • tatiangtatiang Posts: 11,861Member, Sous Chef, PRO, Senior Sous-Chef
    It looks good. Is it working?

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

  • DarkpaxDarkpax Posts: 22Member
    @tatiang yes but only with one spawning actor : i make the spawner to spawn an new random actor when destroy the other on the fild is right.

    and this is the problem . this what i make is working with one spawning acot now , i dont understand how i adjust actors attribute to know what row are active in the table
This discussion has been closed.