AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Dynamic Arrays. (https://forums.alliedmods.net/showthread.php?t=304140)

edon1337 01-05-2018 17:10

Dynamic Arrays.
 
Hello, I read somewhere that this method is incorrect so I'm hoping for someone to tell me the correct one.
What I'm trying to do is not really important, just trying to load Coordinates from an .ini file.

Format of .ini:
Quote:

"models/w_m4a1.mdl" "111.11 222.22 333.33"
Where "111.11 222.22 333.33" is the origin.

If you know a better method than this, feel free to comment.

Code:
enum _:WeaponData {     Weapon_Model[ 32 ],     Float:Weapon_Origin[ 3 ] } new g_iWeapons[ WeaponData ]; public ReadFile( ) {     new szConfigs[ 32 ], szFormat[ 64 ], szWeaponData[ 256 ], szWeaponModel[ 32 ], szWeaponOrigin[ 40 ], szOrigin1[ 12 ], szOrigin2[ 12 ], szOrigin3[ 12 ];     get_configsdir( szConfigs, charsmax( szConfigs ) ) ;         formatex( szFormat, charsmax( szFormat ), "%s/SavedCoordinates.txt", szConfigs ) ;         new iFile = fopen( szFormat, "r" ) ;         if( iFile ) {                 while( ! feof( iFile ) ) {                         fgets( iFile, szWeaponData, charsmax( szWeaponData ) ) ;             trim( szWeaponData ) ;                         parse( szWeaponData, szWeaponModel, charsmax( szWeaponModel ), szWeaponOrigin, charsmax( szWeaponOrigin ) );             strbreak( szWeaponOrigin, szOrigin1, charsmax( szOrigin1 ), szOrigin2, charsmax( szOrigin2 ) );             strbreak( szOrigin2, szOrigin2, charsmax( szOrigin2 ), szOrigin3, charsmax( szOrigin3 ) );                         g_iWeapons[ Weapon_Model ] = szWeaponModel;             g_iWeapons[ Weapon_Origin[ 0 ] ] = str_to_float( szOrigin1 );             g_iWeapons[ Weapon_Origin[ 1 ] ] = str_to_float( szOrigin2 );             g_iWeapons[ Weapon_Origin[ 2 ] ] = str_to_float( szOrigin3 );                         log_to_file( "Test.txt", "%s %f %f %f", szWeaponModel, g_iWeapons[ Weapon_Origin ][ 0 ], g_iWeapons[ Weapon_Origin ][ 1 ], g_iWeapons[ Weapon_Origin ][ 2 ] )                         ArrayPushArray( g_aWeaponOrigins, g_iWeapons );         }                 fclose( iFile ) ;     } }

Quote:

// C:\Users\fujitsu\Desktop\Local Compiling!\CsBattleRoyale.sma(102) : error 028: invalid subscript (not an array or too many subscripts): "Weapon_Origin"
// C:\Users\fujitsu\Desktop\Local Compiling!\CsBattleRoyale.sma(102) : warning 215: expression has no effect
// C:\Users\fujitsu\Desktop\Local Compiling!\CsBattleRoyale.sma(102) : error 001: expected token: ";", but found "]"
// C:\Users\fujitsu\Desktop\Local Compiling!\CsBattleRoyale.sma(102) : error 029: invalid expression, assumed zero
// C:\Users\fujitsu\Desktop\Local Compiling!\CsBattleRoyale.sma(102) : fatal error 107: too many error messages on one line
//
// Compilation aborted.
// 4 Errors.
// Could not locate output file C:\Users\fujitsu\Desktop\Local Compiling!\compiled\CsBattleRoyale.amx (compile failed).
//
// Compilation Time: 0.19 sec
// ----------------------------------------

Press enter to exit ...
Have a nice day and thanks!

OciXCrom 01-05-2018 17:45

Re: Dynamic Arrays.
 
[][] instead of [[]]

edon1337 01-05-2018 17:48

Re: Dynamic Arrays.
 
Quote:

Originally Posted by OciXCrom (Post 2570031)
[][] instead of [[]]

Sorry, I didn't quite understand, can you explain where to replace these brackets?

Like this?
PHP Code:

            g_iWeapons[ ][ Weapon_Origin] ] = str_to_floatszOrigin1 );
            
g_iWeapons[ ][ Weapon_Origin] ] = str_to_floatszOrigin2 );
            
g_iWeapons[ ][ Weapon_Origin] ] = str_to_floatszOrigin3 ); 

Still getting errors.

hleV 01-05-2018 17:52

Re: Dynamic Arrays.
 
Code:
g_iWeapons[ Weapon_Origin[0]]
:arrow:
Code:
g_iWeapons[ Weapon_Origin][0]

edon1337 01-05-2018 17:55

Re: Dynamic Arrays.
 
Quote:

Originally Posted by hleV (Post 2570036)
Code:
g_iWeapons[ Weapon_Origin[0]]
:arrow:
Code:
g_iWeapons[ Weapon_Origin][0]

Oooh, thanks so much guys!

By the way, is there any more efficient way rather than my method? What I did is:
- Read the full origin string from the file
- Strbreak it into 2 pieces
- Strbreak the 2nd part and then win the 3rd one.

But I feel like it's inefficient..

Thanks a bunch!

E1_531G 01-05-2018 18:03

Re: Dynamic Arrays.
 
Save like this:
Quote:

"models/w_m4a1.mdl" "111.11" "222.22" "333.33"
And parse() in 4 parts.

edon1337 01-05-2018 18:28

Re: Dynamic Arrays.
 
Quote:

Originally Posted by E1_531G (Post 2570041)
Save like this:

And parse() in 4 parts.

Hmm nope. I'm already familiar to that method. If it was like that I would've done that already. It might seem confusing to newbies.

EDIT: I'm so stupid, I didn't know parse would work, I was using strbreak for nothing lol. Parse() did the job :)


All times are GMT -4. The time now is 01:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.