Results 1 to 3 of 3

Thread: game[] variable resetting after map_restart

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 08:13.

Posting Permissions

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