Senior Member
|
09-05-2021
, 15:40
File getting line and then use parse
|
#1
|
Hello, i've been trying to figure out for hours why my File reading code isn't working properly and i'm really tired ... i've benn trying to print the results out and see what i get
The code i'll post below is about 3 numbers ("0 0 0" *next line* "166 166 166" *next line* "255 255 255") that im gonna use for a hudmessage, everything works fine until the string goes into parse:
- Console print debugging results:
Code:
[ZUC] - 21 - szBuffer = "0 0 0"
[ZUC] - 22 - szBuffer = "0 0 0"
[ZUC] - 23 - szBuffer = 0 0 0
[ZUC] - 24 - szBuffer = 0 0 0 , szR, szG, and szB = , ,
[ZUC] - 25 - szBuffer = 0 0 0 , szR, szG, and szB = 0, 0, 0
[ZUC] - 25 - szBuffer = 0 0 0 , r, g, and b = 0, 0, 0
[ZUC] - 21 - szBuffer = "166 166 166"
[ZUC] - 22 - szBuffer = "166 166 166"
[ZUC] - 23 - szBuffer = 166 166 166
[ZUC] - 24 - szBuffer = 166 166 166 , szR, szG, and szB = , ,
[ZUC] - 25 - szBuffer = , szR, szG, and szB = , , 166
[ZUC] - 25 - szBuffer = , r, g, and b = 0, 166, 166
[ZUC] - 21 - szBuffer = "255 255 255"
[ZUC] - 22 - szBuffer = "255 255 255"
[ZUC] - 23 - szBuffer = 255 255 255
[ZUC] - 24 - szBuffer = 255 255 255 , szR, szG, and szB = , ,
[ZUC] - 25 - szBuffer = , szR, szG, and szB = , , 255
[ZUC] - 25 - szBuffer = , r, g, and b = 0, 255, 255
Code:
Code:
load_configs()
{
new szPath[50], szBuffer[512]
new szR[3], szG[3], szB[3]
new file
formatex(szPath, charsmax(szPath), "addons/amxmodx/configs/%s", CONFIG_FILE)
if(!file_exists(szPath)){
file = fopen(szPath, "a")
fputs(file, "@ You may follow the following format to succesfully add you color^n")
fputs(file, "@ ^"50 20 100^"^n")
fputs(file, "@ Enjoy!^n")
fputs(file, "^"0 0 0^"")
fclose(file)
}
file = fopen(szPath, "rt")
while(!feof(file))
{
fgets(file, szBuffer, charsmax(szBuffer))
server_print("[ZUC] - 11 - szBuffer = %s", szBuffer)
trim(szBuffer)
server_print("[ZUC] - 12 - szBuffer = %s", szBuffer)
remove_quotes(szBuffer)
server_print("[ZUC] - 13 - szBuffer = %s", szBuffer)
if(szBuffer[0] == '@' || szBuffer[0] == ';' || !szBuffer[0]) continue;
server_print("[ZUC] - 14 - szBuffer = %s , szR, szG, and szB = %s, %s, %s", szBuffer, szR, szG, szB)
parse(szBuffer, szR, 3, szG, 3, szB, 3)
server_print("[ZUC] - 15 - szBuffer = %s , szR, szG, and szB = %s, %s, %s", szBuffer, szR, szG, szB)
r[0][clrcount[0]] = str_to_num(szR)
g[0][clrcount[0]] = str_to_num(szG)
b[0][clrcount[0]] = str_to_num(szB)
server_print("[ZUC] - 15 - szBuffer = %s , r, g, and b = %i, %i, %i", szBuffer, r[0][clrcount[0]], b[0][clrcount[0]], b[0][clrcount[0]])
szR = ""
szG = ""
szB = ""
clrcount[0]++
}
formatex(szPath, charsmax(szPath), "addons/amxmodx/configs/%s", CONFIG_FILE2)
if(!file_exists(szPath)){
file = fopen(szPath, "a")
fputs(file, "@ You may follow the following format to succesfully add you color^n")
fputs(file, "@ ^"50 20 100^"^n")
fputs(file, "@ Enjoy!^n")
fputs(file, "^"0 0 0^"")
fclose(file)
}
file = fopen(szPath, "rt")
while(!feof(file))
{
fgets(file, szBuffer, charsmax(szBuffer))
server_print("[ZUC] - 21 - szBuffer = %s", szBuffer)
trim(szBuffer)
server_print("[ZUC] - 22 - szBuffer = %s", szBuffer)
remove_quotes(szBuffer)
server_print("[ZUC] - 23 - szBuffer = %s", szBuffer)
if(szBuffer[0] == '@' || szBuffer[0] == ';' || !szBuffer[0]) continue;
server_print("[ZUC] - 24 - szBuffer = %s , szR, szG, and szB = %s, %s, %s", szBuffer, szR, szG, szB)
parse(szBuffer, szR, 3, szG, 3, szB, 3)
server_print("[ZUC] - 25 - szBuffer = %s , szR, szG, and szB = %s, %s, %s", szBuffer, szR, szG, szB)
r[1][clrcount[1]] = str_to_num(szR)
g[1][clrcount[1]] = str_to_num(szG)
b[1][clrcount[1]] = str_to_num(szB)
server_print("[ZUC] - 25 - szBuffer = %s , r, g, and b = %i, %i, %i", szBuffer, r[1][clrcount[1]], b[1][clrcount[1]], b[1][clrcount[1]])
szR = ""
szG = ""
szB = ""
clrcount[1]++
}
}
AmxModX Version: 1.8.3-dev+5201
Expectations: Remove the quotes from the line, check if the line is not a comment or if there's something in it or if there is any @, split the 3 numbers in 3 strings and then add the numbers to the variable which stores them
Last edited by AnimalMonster; 09-05-2021 at 16:01.
|
|