Topic: Making a private variable persistant

I'm currently working on an object for SD which must be able to spawn other objects only every so often, but I've run into an issue.  Whenever I have it grab a value from a global and store it in a private variable and reset the level it loses the variable.  Because of the way SD works, I've got to have the ability to make a variable persistent without storing it in a global variable; I'm working under the assumption that there will be N of these spawners in any given level and having them all read and modify the same global will be disastrous.  Anyone have any ideas?

If I knew then what I know now I'd tell you that the story's true.  Cause whatever you do, it comes back to you.  -Slaughter, Burning Bridges

Re: Making a private variable persistant

What's the range of this variable? Maybe you can pack several values into one.

.. or you can just use more states.

Re: Making a private variable persistant

Here, I'll post my scripts so that you can see what I'm talking about:

object "weekly_enemy_spawner_green_ninja"

{

    requires 0.2.0

    always_active

    category "weekly_enemy_spawners"

    state "main"

        {

            set_animation SD_BIGRING 0

            if "$initilized" "wait"

            change_state "spawn"

        }

    state "set_date" //transfers the current "day" into a private variable.

        {

            let "$date = $_date"

            let "$initilized = 1"

            change_state "wait"

        }

    state "wait"

        {

            if "$_date-$date >= 7" "spawn"

        }

    state "spawn"

        {

            create_child "ENEMY_green_ninja"

            change_state "set_date"

        }

}

object "daily_enemy_spawner_green_ninja"

{

    requires 0.2.0

    always_active

    category "daily_enemy_spawners"

    state "main"

        {

            set_animation SD_BIGRING 0

            if "$initilized" "wait"

            change_state "spawn"

        }

    state "set_date"

        {

            let "$date = $_date"

            let "$initilized = 1"

            change_state "wait"

        }

    state "wait"

        {

            if "$_date-$date >= 1" "spawn"

        }

    state "spawn"

        {

            create_child "ENEMY_green_ninja"

            change_state "set_date"

        }

}

object "hourly_enemy_spawner_green_ninja"

{

    requires 0.2.0

    always_active

    category "hourly_enemy_spawners"

    state "main"

        {

            set_animation SD_BIGRING 0

            if "$initilized" "wait"

            change_state "spawn"

        }

    state "set_date"

        {

            let "$hour = $_hours"

            let "$initilized = 1"

            change_state "wait"

        }

    state "wait"

        {

            if "$_hours-$hour >= 1" or "$_hours -$hour == 24" "spawn"

        }

    state "spawn"

        {

            create_child "ENEMY_green_ninja"

            change_state "set_date"

        }

}
If I knew then what I know now I'd tell you that the story's true.  Cause whatever you do, it comes back to you.  -Slaughter, Burning Bridges

Re: Making a private variable persistant

one possible solution would be...

for each copy of weekly_enemy_spawner_green_ninja, you can have an unique private value called $id, which assumes values like 1, 2, 3, ...

depending on the $id, you copy a global variable ($_var_1, $_var_2, ...) to a private variable ($my)

Re: Making a private variable persistant

Alexandre wrote:

one possible solution would be...

for each copy of weekly_enemy_spawner_green_ninja, you can have an unique private value called $id, which assumes values like 1, 2, 3, ...

depending on the $id, you copy a global variable ($_var_1, $_var_2, ...) to a private variable ($my)

Would this mean that I would need to create a separate object for each enemy spawner in the game?  If so, is there no more programmer-friendly solution?

If I knew then what I know now I'd tell you that the story's true.  Cause whatever you do, it comes back to you.  -Slaughter, Burning Bridges

Re: Making a private variable persistant

lunarrush wrote:

Would this mean that I would need to create a separate object for each enemy spawner in the game?

No. You use a share variable to control which objects receive which ids.

Re: Making a private variable persistant

Alexandre wrote:

No. You use a share variable to control which objects receive which ids.

So basically the goal would be to have a global named for each spawner?  Is it possible to name a variable using a variable such as:

...
let "$_id$_global_id_number = N"
...

Last edited by lunarrush (2011-04-27 22:34:15)

If I knew then what I know now I'd tell you that the story's true.  Cause whatever you do, it comes back to you.  -Slaughter, Burning Bridges

Re: Making a private variable persistant

yes, one global var for each instance. you could use some IFs to decide which global var to take.

alternatively, you can pack multiple values in only one variable. KZR has described such a technique somewhere.