SA-MP Forums Archive
sscanf - d identifier gets the wrong number - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: sscanf - d identifier gets the wrong number (/showthread.php?tid=592367)



sscanf - d identifier gets the wrong number - BKarner - 23.10.2015

I'm trying to get a string, and pull it into several variables. The string I'm using is:

Код:
10379, -2699.87451, 374.68600, 12.71875,   356.85840, 0.00000, 3.14159
The following code:

Код:
if(sscanf(stringBuffer, "p<,>dffffffD(-1)D(-1)D(-1)F(300.0)", modelID, ox, oy, oz, orx, ory, orz, worldID, interiorID, playerid, streamdistance) != -1){
    CreateDynamicObject(modelID, ox, oy, oz, orx, ory, orz, worldID, interiorID, playerid, streamdistance);
    printf("(Create) modelID: %d | ox: %f | oy: %f | oz: %f", modelID, ox, oy, oz);
    LOADED_OBJECT_COUNT++;
}
I want it to produce the following:

Код:
"(Create) modelID: 10379 | ox: -2699.874511 | oy: 374.686004 | oz: 12.718750
What I get is:

Код:
"(Create) modelID: 1 | ox: -2699.874511 | oy: 374.686004 | oz: 12.718750
Why do I only get 1? Instead of the correct modelID?


Re : sscanf - d identifier gets the wrong number - Golimad - 23.10.2015

can you try "i" instead of "d" even tho they are the same?


Re: Re : sscanf - d identifier gets the wrong number - BKarner - 23.10.2015

Quote:
Originally Posted by Golimad
Посмотреть сообщение
can you try "i" instead of "d" even tho they are the same?
I tried D, I, N and F.

F returns 0.0000
D returns 1
I returns 1
N returns n
A floored F returned 1.


Re: sscanf - d identifier gets the wrong number - AbyssMorgan - 24.10.2015

my test
PHP код:
    new stringBuffer[256], LOADED_OBJECT_COUNT 0,
    
modelIDFloat:oxFloat:oyFloat:ozFloat:orxFloat:oryFloat:orzworldIDinteriorIDplayeridFloat:streamdistance;
    
    
stringBuffer "10379, -2699.87451, 374.68600, 12.71875,   356.85840, 0.00000, 3.14159";
    
    if(
sscanf(stringBuffer"p<,>dffffffD(-1)D(-1)D(-1)F(300.0)"modelIDoxoyozorxoryorzworldIDinteriorIDplayeridstreamdistance) != -1){
        
CreateDynamicObject(modelIDoxoyozorxoryorzworldIDinteriorIDplayeridstreamdistance);
        
printf("(Create) modelID: %d | ox: %f | oy: %f | oz: %f"modelIDoxoyoz);
        
LOADED_OBJECT_COUNT++;
    } 
results
PHP код:
[16:49:28] (CreatemodelID10379 ox: -2699.874511 oy374.686004 oz12.718750 



Re: sscanf - d identifier gets the wrong number - BKarner - 24.10.2015

The issue was, modelID was being overriden by an enum declaration. So it was always 1. I feel so stupid, Thanks for letting my know it wasn't the loading code Abyss, I really appreciate it.

+Rep