Edit attribute of spawned object

TangoDownStudiosTangoDownStudios Member Posts: 46
edited November -1 in Working with GS (Mac)
Is it possible to edit the attribute of a spawned object? For example I have a gun that shoots bullet actors, can I change the spawned bullet actors color inside of my gun actor?

Also if my gun were to become "destroyed" is it possible to destroy all bullets that were spawned with that gun?

This is incredibly easy if I were programming the system, but since GS is a level of abstraction above programming the game I'm not sure how to go about doing this.

*Please do not recommend using global variables (Its the wrong way of doing things) Unless there really is no other way

If I were to be able to set attributes I could essentially store a "pointer" to a parent object with the save/read attribute behaviors. All I would need to do is set the child's parent value to the parents tag. This is a dodgy way of doing it but its the closest I can come to parent-child relationships

Any and all help is welcome!

Comments

  • MotherHooseMotherHoose Member Posts: 2,456
    Yes it is possible...to change attributes of spawned actors.
    Yes it is possible to destroy the bullets that were spawned when the gun is destroyed.

    This is incredibly easy in GameSalad.

    you are allowing other programming systems to distract you from the easy way to do things in GS.

    consider the gun actor the parent... and the bullet actor the child
    have the gun actor change the attributes on the bullet actor using globalAttributes as needed
    (that is actually a save/read behavior... the gun(parent) changes and saves states and the bullet(child) reads and obeys states)

    GS handles a large volume of globals extremely fast and efficiently.

    I for one do not understand the your reasons for not wanting to use globals... the computer does not reference/manipulate state until you code/tell it to do so...they just sit there to you till you want them to check or change something...

    if implementing behavior method other than spawn ... you can directly change other actors attributes without the globals...by coding the instant of the actor using expression to access the attributes you want to manipulate.

    MH
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Thank you for your response MotherHoose, would you be able to explain what you meant in your last paragraph?

    And by using global variables your confined to hardcoding them into the software which is why I find them so evil. You can use the Save/Read behaviors and that's fine but you can't reference an objects parent like that because you'd need to create a custom key for every object, then save that key into the spawned childs attributes list, and there is no way of doing this globally.

    I understand that just because their are a large AMOUNT of globals it won't directly affect the games performance, I'm saying that by using globals your severely limiting the potential of games by not allowing dynamic parent/child relationships.

    I've deliberated all night, but I can't figure out how to use globals to achieve a true dynamic parent/child hierarchy.

    Perhaps you can enlighten me?
  • MotherHooseMotherHoose Member Posts: 2,456
    ah but you can use behaviors Save Attribute and Load Attribute at anytime in your game...

    on your bullet actor in the actor pane:
    create a Rule with no conditions (so nothing triggers it)
    in the behavior area of that Rule
    drag in Change Attribute
    [expression] self.Color.Red To: 0
    under that drag in a Save Attribute and name it or just assign a key

    do a Rule for any changes you wish including Destroy this Actor

    good idea to drag in a Note behavior and list your names/keys and what they do...
    and when you are finished ... rename it Bullet Keys (double click on where it says Note) then drag that Note to MyBehaviors

    on your gun Actor in actor pane:
    drag in your Note and reference for when you want to trigger an event on the bullet
    and use Load Attribute behavior to do so...

    try it... it is easy! and as dynamic as it gets!

    ===Re changing other actors' attributes in a scene

    I am going to ask you to try this out
    open a New project
    Create 2 Actors
    drag to sceneScreen...
    click on one of the Actors in the scene...unlock it
    Create a Rule when touch is pressed
    --Change Attribute [expression] and see in the list CurrentScene>Layers>Background>both actors!
    click the other actor... and see its attributes... click one and change it

    Preview and make it happen!
    that's it! and that's as dynamic as it gets!

    Hardest thing was learning that things get done a little differently in GS and the naming of things is correct but so very different from other programming environments...

    MH
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Thank you again for your reply!

    The problem isn't accessing an actor inside the current scene, its creating one on the fly.

    I don't think this is as dynamic as you think it is...

    How would you access actors made on the fly? Like during runtime
  • MotherHooseMotherHoose Member Posts: 2,456
    I might use xcode... but then I wouldn't be able to visualize the layout in interface builder...
    maybe it has changed but last year could NOT orientate the iPad to Landscape in IB... so I came over to GS.

    actually, probably would throw a blank actor on the scene grey-area and use another actor/event to trigger a change of it's attributes as needed...

    MH
    EDIT: like your Rotate demo!
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    TangoDownStudios said:
    Thank you again for your reply!

    The problem isn't accessing an actor inside the current scene, its creating one on the fly.

    I don't think this is as dynamic as you think it is...

    How would you access actors made on the fly? Like during runtime

    create a game boolean attribute called game.DestroyBullet

    in the gun:

    Rule - when overlaps with actor type "gunkiller"
    change game.DestroyBullet to 1
    destroy actor

    in bullet:
    Rule - when game.DestroyBullet is true
    destroy actor

    so when the gun is destroyed it changes that game attribute which then causes every bullet to destroy itself.
Sign In or Register to comment.