Raised This Month: $ Target: $400
 0% 

Removing hard coded paths...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DoubleTap
Veteran Member
Join Date: Mar 2004
Location: Harker Heights, TX
Old 04-07-2004 , 10:22   Removing hard coded paths...
Reply With Quote #1

In my efforts to actually learn some code, I am trying to start taking the hard coding off my ported plugins to make them compatible. This is all new to me but I am trying to apply logic and need help.

I need to remove hard coded paths (in this example from my latest port, Jedi Theme Punish).

Example:

if(file_exists("addons/amxx/custom/ejl_hud_colors.ini") == 1){
while((line=read_file("addons/amxx/custom/ejl_hud_colors.ini",line,data,100,stxtsize))! =0){

I looked thru other plugins that I know use other files and think I have a clue, but want confirmation.

I see in the Swear Filter Plugin this:

new szWord[MAX_WORD_LENGTH]
format( g_szBadWordFile, 63, "%s/swear/swearwords.ini", g_szCustomDir )
format( g_szGoodWordFile, 63, "%s/swear/goodwords.ini", g_szCustomDir )

get_customdir( g_szCustomDir, 31 )
get_configsdir( g_szConfigDir, 31 )
server_cmd( "exec %s/swear/swear_config.cfg;", g_szCustomDir )
server_cmd("exec %s/mysql.cfg;", g_szConfigDir )

And at the beginning of his code:

// Path to AMXX Custom & Config Directories
new g_szCustomDir[32]
new g_szConfigDir[32]

Looking at these examples I believe I see him establishing the non hard coded paths using the above listed commands. One pointing to the configs folder and the other to the custom folder. I need the custom paths version so I think this should be my code:

new g_szCustomDir[32]

if(file_exists("%s/ejl_hud_colors.ini;", g_szCustomDir ) == 1){
while((line=read_file("%s/ejl_hud_colors.ini",line,data,100,stxtsize))! =0){

Well, here is where logic fails and coding knowledge is needed... the first line "appears" right to me as it was a simple copy his example. The second line has additional commands which make it hard for a non-coder to understand where the "g_szCustomDir" would go without breaking the line.

Am I on the right track on either line, what would I need to fix the second part of it ?

Vic/DT
__________________
DoubleTap is offline
Send a message via ICQ to DoubleTap
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 04-07-2004 , 10:29  
Reply With Quote #2

Code:
new g_szCustomDir[32] if(file_exists("%s/ejl_hud_colors.ini;", g_szCustomDir ) == 1){ while((line=read_file("%s/ejl_hud_colors.ini",line,data,100,stxtsize))!=0){

Well that would be wrong, becuase the read_file line would read the %s as "line" soo it would be something like

Code:
new g_szCustomDir[32] if(file_exists("%s/ejl_hud_colors.ini;", g_szCustomDir ) == 1){ while((line=read_file("%s/ejl_hud_colors.ini", get_szCustomDir,line,data,100,stxtsize))!=0){

Also if you plan to use that make sure you have

get_customdir( g_szCustomDir, 31 )

defined before.
__________________

BigBaller is offline
DoubleTap
Veteran Member
Join Date: Mar 2004
Location: Harker Heights, TX
Old 04-07-2004 , 10:33  
Reply With Quote #3

That makes sense man... why on the second line is "get_szCustomDir" used instead of "szCustomDir" like on the first line... keep in mind a non-coder here

Vic/DT
__________________
DoubleTap is offline
Send a message via ICQ to DoubleTap
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 04-07-2004 , 10:35  
Reply With Quote #4

lol might just be a typo man, im sick soo I cant really thing as to why right now, maybe bailopan could shed some light on the matter.
__________________

BigBaller is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 04-07-2004 , 10:39  
Reply With Quote #5

Quote:
Originally Posted by BigBaller
Code:
new g_szCustomDir[32] if(file_exists("%s/ejl_hud_colors.ini;", g_szCustomDir ) == 1){ while((line=read_file("%s/ejl_hud_colors.ini", get_szCustomDir,line,data,100,stxtsize))!=0){
You can't pass g_szCustomDir to read_file, since it doesn't accept such a parameter...
My suggestion is:
Code:
new szCustomDir[32] new szFile[64] get_customdir( szCustomDir, 31 ) format( szFile, 63, "%s/ejl_hud_colors.ini", szCustomDir ) if(file_exists( szFile ) == 1){ while((line=read_file( szFile, line, data, 100, stxtsize ))!=0) //...
xeroblood is offline
Send a message via MSN to xeroblood
DoubleTap
Veteran Member
Join Date: Mar 2004
Location: Harker Heights, TX
Old 04-07-2004 , 10:46  
Reply With Quote #6

Okay... brain sizzling now... but I have to understand what you did too... I establish the file and path at the beginning of the code, and allocate the block size for later usage. LATER I "get" the folder and look for the file there. It's not all clicking, when to use path again and when not to... but I am going to try and fix the whole file and post here. I won't publish the "fix" until you guys have had a chance to look at it.

Thanks...

Vic/DT
__________________
DoubleTap is offline
Send a message via ICQ to DoubleTap
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 04-07-2004 , 11:06  
Reply With Quote #7

headaches are a bitch haha, thanks for the correction xero
__________________

BigBaller is offline
DoubleTap
Veteran Member
Join Date: Mar 2004
Location: Harker Heights, TX
Old 04-07-2004 , 11:06  
Reply With Quote #8

Okay, basically copied straight (I think) from what you suggested xeroblood and I get three errors:

Quote:
Small compiler 2.1.0 Copyright (c) 1997-2002, ITB CompuPhase

amx_ejl_jedipunish.sma(461) : warning 217: loose indentation
amx_ejl_jedipunish.sma(466) : warning 217: loose indentation
amx_ejl_jedipunish.sma(471) : error 010: invalid function or declaration

1 Error.
I know warnings "may" be harmless... but the third one stopped it from working... please take a look at the file.

Vic/DT
__________________
DoubleTap is offline
Send a message via ICQ to DoubleTap
dragonchaos
Member
Join Date: Mar 2004
Old 04-07-2004 , 11:24  
Reply With Quote #9

Line 464:
Code:
while((line=read_file( szFile, line, data, 100, stxtsize ))!=0){

added { at the end ... i think that will stop the error (compiled with the 2 warnings and no error(s))

as for the warnings, on line 461 and 462 just take out the extra space, and the warnings will be gone ...
dragonchaos is offline
DoubleTap
Veteran Member
Join Date: Mar 2004
Location: Harker Heights, TX
Old 04-07-2004 , 11:28  
Reply With Quote #10

That took out the error... I guess I need to know what to look for

I also got rid of the indentation warnings using trial and error...

Vic/DT

Thanks for the help... I got other plugins I am going to need to do similar for...
__________________
DoubleTap is offline
Send a message via ICQ to DoubleTap
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 13:47.


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