serthy
10th October 2016, 08:10
I have the following code:
Init()
{
doexit = false;
if( !isDefined( game[ "init" ] ) )
{
game[ "ranks" ] = [];
game[ "rank" ] = [];
LoadRanks();
doexit = true;
}
/#
printf( "game[ ranks ].size = %\n" , game[ "ranks" ].size );
printf( "game[ rank ].size = %\n" , game[ "rank" ].size );
assert( game[ "rank" ].size > 0 );
assert( game[ "ranks" ].size > 0 );
#/
if( doexit ) // simulates s&d round-end
{
wait( 5.0 );
printf( "game[ ranks ].size = %\n" , game[ "ranks" ].size );
printf( "game[ rank ].size = %\n" , game[ "rank" ].size );
wait( 0.05 );
map_restart( true );
}
}
LoadRanks()
{
ranks = SqlQuery_GetRankForType( "account_group" );
for( j = 0 ; j < ranks.rows.size ; j++ )
{
rank = spawnStruct();
rank.ranklevel = int( ranks.rows[ j ][ "Rank" ] );
rank.name = toLower( ranks.rows[ j ][ "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)?
Init()
{
doexit = false;
if( !isDefined( game[ "init" ] ) )
{
game[ "ranks" ] = [];
game[ "rank" ] = [];
LoadRanks();
doexit = true;
}
/#
printf( "game[ ranks ].size = %\n" , game[ "ranks" ].size );
printf( "game[ rank ].size = %\n" , game[ "rank" ].size );
assert( game[ "rank" ].size > 0 );
assert( game[ "ranks" ].size > 0 );
#/
if( doexit ) // simulates s&d round-end
{
wait( 5.0 );
printf( "game[ ranks ].size = %\n" , game[ "ranks" ].size );
printf( "game[ rank ].size = %\n" , game[ "rank" ].size );
wait( 0.05 );
map_restart( true );
}
}
LoadRanks()
{
ranks = SqlQuery_GetRankForType( "account_group" );
for( j = 0 ; j < ranks.rows.size ; j++ )
{
rank = spawnStruct();
rank.ranklevel = int( ranks.rows[ j ][ "Rank" ] );
rank.name = toLower( ranks.rows[ j ][ "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)?