Enter attributes as a function

danayeldanayel Member Posts: 25
edited November -1 in Working with GS (Mac)
Is it possible to change or select attribute names by building them with a function?

eg. I have 6 actors on the screen, and each one has identical rules except that the attributes they access are numbered 1-6

shape_1
shape_2
shape_3
..
shape_6

Rather than having to manually edit every single one of them and change them from the prototype, which makes a lot more work if I want to change the prototype, could I instead give them each an attribute of self.id and reference the game level attributes as:

"game.shape_"+self.id

This would make development a LOT faster and much easier to make changes when there are a lot of identical actors on the screen.

Comments

  • synthesissynthesis Member Posts: 1,693
  • danayeldanayel Member Posts: 25
    Thanks Synthesis, but that isn't quite what I mean.

    I am already using that logic to alter images on the fly, but this is different.

    I have 6 actors on the screen, all do the exact same rules, except to different attributes.

    Because of this I want to have the attribute names dynamic. Otherwise I need to edit them all to point at different attributes.

    e.g. imagine you have 6 buttons, each one turns a different light on and off.

    if (pressed inside) -> change(game.button1 to 'on')
    if (pressed inside) -> change(game.button2 to 'on')
    if (pressed inside) -> change(game.button3 to 'on')
    ...

    Because actors can't talk to each other, I would need to set the game attributes which are read by the lights so they know to turn on/off. But I need to map one button to one light.

    The other option would be to use some sort of mock binary :

    010010 = lights 2 and 5 are on

    Which I am doing already for some attributes, but in my game there are 36 "lights" and I can't write an int that is 36 digits long...

    Hence I have location 1-6 and position (at that location) 1-6

    But I still need to read 6 attributes, one for each location. The position-values are stored in mock binary in the game.location1 ... game.location6 attributes
  • synthesissynthesis Member Posts: 1,693
    Sounds like you are trying to do a suedo-array or do object oriented buttons.

    GS is pretty dumb when it comes to attributes. They need to ALL be defined in the core settings...GS cannot create an attribute (or define an attribute definition) during runtime. Nor can it call a function or an attribute from another actor (something everyone wants). The actors can ONLY currently talk to the game or to themselves.

    I recommend build the base values...then use actor IDs. to assign the unique values to the standard attribute containers...thus making each actor's values unique...but all using the same attribute names.

    Otherwise...you will need 6 sets of unique attributes.

    TIP:
    When posting...do not use advanced "CODING JARGON" or problem presentation structure as most of the people on here will not know what you are talking about and will not be able to help. Keep it in layman's terms and more people can help...and learn from the thread. For example...there is not such thing as a function in GameSalad. There are rules and behaviors. Also...the "mock binary" thing will send 90% of the readers packing. =)
  • danayeldanayel Member Posts: 25
    Thanks Synthesis,

    I thought that is what I would have to do, but hoped I had simply missed something.

    I already built it to work like this, but I was just creating my actor instances and changing all the attributes in the rules and I got to wondering if there wasn't a better way, because it is taking me aaaages to do. Thinking up the rules was faster...

    As for your tip. I shall attempt to. Old habits die hard though so please forgive me if I transgress again.
  • ORBZORBZ Member Posts: 1,304
    don't forget about the "Scene" scope. Scene scoped actors can "reach inside" of other actors and manipulate their properties. In this way they can facilitate cross-talk between actors without globals.

    Not saying this helps your situation, but it's important to remember the Scene scope.
  • synthesissynthesis Member Posts: 1,693
    Unfortunately you have to "unlock" the actor to do that.
  • danayeldanayel Member Posts: 25
    Thanks Orbz, I didn't know that. That isn't quite what I was asking about, but it may just help me in other areas.

    My game only has one scene and most of the actors are already unlocked (for the reasons above) so it might be useful.

    Thanks again also Synthesis.
  • netdzynrnetdzynr Member Posts: 296
    Hi danayel:

    It sounds like we're trying to do similar things. I found a solution that still needs some testing on actual devices but might work for you: use a non-visible actor in the scene to track the states of other actors.

    http://gamesalad.com/forums/topic.php?id=4672
  • adadoadado Member Posts: 219
    More info here about scene unlocked actor-to-actor communication:

    http://gamesalad.com/forums/topic.php?id=4672

    It's still a manual process wiring them up, it does unlock and unsync from the prototype, has to be done per scene, and can cause headaches when the actor's involved and/or scene they are in need updating. However, it can provide some relief in certain situations.
  • adadoadado Member Posts: 219
    Ugh, netdyznr posted it.

    <must read whole thread before posting, must read whole thread before posting...>

    :-)
Sign In or Register to comment.