Raised This Month: $32 Target: $400
 8% 

Solved Dynamic Arrays.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-05-2018 , 17:10   Dynamic Arrays.
Reply With Quote #1

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!
__________________

Last edited by edon1337; 01-05-2018 at 18:29.
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-05-2018 , 17:45   Re: Dynamic Arrays.
Reply With Quote #2

[][] instead of [[]]
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-05-2018 , 17:48   Re: Dynamic Arrays.
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
[][] 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.
__________________

Last edited by edon1337; 01-05-2018 at 17:50.
edon1337 is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 01-05-2018 , 17:52   Re: Dynamic Arrays.
Reply With Quote #4

Code:
g_iWeapons[ Weapon_Origin[0]]

Code:
g_iWeapons[ Weapon_Origin][0]
__________________
hleV is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-05-2018 , 17:55   Re: Dynamic Arrays.
Reply With Quote #5

Quote:
Originally Posted by hleV View Post
Code:
g_iWeapons[ Weapon_Origin[0]]

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!
__________________
edon1337 is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 01-05-2018 , 18:03   Re: Dynamic Arrays.
Reply With Quote #6

Save like this:
Quote:
"models/w_m4a1.mdl" "111.11" "222.22" "333.33"
And parse() in 4 parts.
__________________
My English is A0
E1_531G is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-05-2018 , 18:28   Re: Dynamic Arrays.
Reply With Quote #7

Quote:
Originally Posted by E1_531G View Post
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
__________________

Last edited by edon1337; 01-06-2018 at 06:34.
edon1337 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:56.


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