Results 1 to 3 of 3

Thread: game[] variable resetting after map_restart

  1. #1
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts

    game[] variable resetting after map_restart

    I have the following code:

    PHP Code:
    Init()
    {
        
    doexit false;

        if( !
    isDefinedgame"init" ] ) )
        {
            
    game"ranks" ] = [];
            
    game"rank" ] = [];

            
    LoadRanks();

            
    doexit true;
        }

        /
    #
            
    printf"game[ ranks ].size = %\n" game"ranks" ].size );
            
    printf"game[ rank ].size = %\n" game"rank" ].size );

            
    assertgame"rank" ].size );
            
    assertgame"ranks" ].size );
        
    #/

        
    if( doexit // simulates s&d round-end
        
    {
            
    wait5.0 );

            
    printf"game[ ranks ].size = %\n" game"ranks" ].size );
            
    printf"game[ rank ].size = %\n" game"rank" ].size );

            
    wait0.05 );

            
    map_restarttrue );
        }
    }

    LoadRanks()
    {
        
    ranks SqlQuery_GetRankForType"account_group" );

        for( 
    ranks.rows.size j++ )
        {
            
    rank spawnStruct();
            
    rank.ranklevel intranks.rows][ "Rank" ] );
            
    rank.name toLowerranks.rows][ "Name" ] );
            
    rank.id game"ranks" ].size;

            
    game"ranks" ][ rank.id ] = rank;
            
    game"rank" ][ rank.name ] = rank.id;
        }

    This loads the ranks from a mysql table to the game-variables.
    I wanted to avoid loading the ranks every round on S&D, so i stored the information in the game[] variable rather than in the level.variable.
    However: after a map_restart the game[ ranks ] array is empty (size = 0) and the game[ rank ] array stays filled. (in the code example, the 2nd assert fires)

    I do not delete the array in my code (after 5 seconds, before the map_restart, the array is still filled
    I renamed "ranks" to "test_ranks", as maybe the name is special and overritten by the engine, but the result is the same

    Am I missing something?
    Do I misuse the game-variable?

    Maybe only primitive types can be stored across a map_restart (and not spawnstructs)?
    Last edited by serthy; 10th October 2016 at 09:13.

  2. #2
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    In fast_restart (new round of sd) a .pers variable is persistent. Everything else will have a reset if im correct

  3. #3
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    game should also be persistent.

    Not sure about the spawnstructs though, try storing it in arrays instead.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •