Float Fehler?

Wichtiger Hinweis: Bitte ändert nicht manuell die Schriftfarbe auf schwarz sondern belasst es bei der Standardeinstellung. Somit tragt ihr dazu bei dass euer Text auch bei Verwendung unseren dunklen Forenstils noch lesbar ist!

Tipp: Ihr wollt längere Codeausschnitte oder Logfiles bereitstellen? Benutzt unseren eigenen PasteBin-Dienst Link
  • Abend,
    warum liest er mir den Float nicht bzw falsch aus?
    stock LoadTankstellen()
    {


    new
    idx = 0,
    result[500];
    format(result, 128, "SELECT * FROM tankstellen");
    print(result);
    new ttid,ow[MAX_PLAYER_NAME],Float:pos[3],Float:i[3],bp,v,lp,ond;
    mysql_query(result);
    mysql_store_result();
    new string[256];
    while(mysql_fetch_row_format(result, "|"))

    {
    sscanf(result, "p<|>is[30]ffffffiiii",ttid,ow,pos[0],pos[1],pos[2],i[0],i[1],i[2],bp,v,lp,ond);
    print(result);
    Tanke[idx][id] = ttid;
    Tanke[idx][owner] = ow;
    Tanke[idx][buypreis] = bp;
    Tanke[idx][iconx] = pos[0];//
    Tanke[idx][icony] = pos[1];//
    Tanke[idx][iconz] = pos[2];// Wird alles nicht geladen. Float: 0.0000 0.0000 0.0000, anstatt den richtigen Coords
    Tanke[idx][kx] = i[0];//
    Tanke[idx][ky] = i[1];//
    Tanke[idx][kz] = i[2];//
    Tanke[idx][vorrat] = v;
    Tanke[idx][literpreis] = lp;
    Tanke[idx][owned] = ond;
    CreatePickup(1274,1,Tanke[idx][iconx],Tanke[idx][icony],Tanke[idx][iconz],0);

    if(Tanke[idx][owned] == 1)
    {
    format(string,sizeof(string),"Tanke %i\nKaufpreis %i", Tanken, bp);
    }
    else
    {
    format(string,sizeof(string),"Tanke %i\nBesitzer %s\nLiterpreis %i\n %i /1000l",Tanken,Tanke[idx][owner],lp,v);
    }
    Create3DTextLabel(string,0xFFFFFFFF,Tanke[idx][iconx],Tanke[idx][icony],Tanke[idx][iconz],30,0,0);
    idx++;
    printf(" >> %i Tankstellen geladen!", idx);


    }
    print(result);
    mysql_free_result();
    return 1;
    }/*


    MFG

  • Es kann daran liegen, dass MAX_PLAYER_NAME nicht 30 ist, sondern 24.
    sscanf(result, "p<|>is[24]ffffffiiii",ttid,ow,pos[0],pos[1],pos[2],i[0],i[1],i[2],bp,v,lp,ond);


    Wenn das nicht tut, dann nimm die manuelle Methode, die finde ich so wie so viel besser als sscanf, weil man weiß was der Code macht.


    strins(result, "|", strlen(result));
    new oldi=0;
    new count=0;
    for(new i=0; i<strlen(result); i++)
    {
    if(result[i]=='|')
    {
    count++;
    new tmpstring[sizeof(result)]; tmpstring=result;
    strdel(tmpstring, i, strlen(tmpstring));
    strdel(tmpstring, 0, oldi+1);
    switch(count)
    {
    case 1: ttid = strval(tmpstring);
    case 2: format(ow, sizeof(ow), "%s", tmpstring);
    case 3: pos[0] = floatstr(tmpstring);
    case 4: pos[1] = floatstr(tmpstring);
    case 5: pos[2] = floatstr(tmpstring);
    case 6: i[0] = floatstr(tmpstring);
    case 7: i[1] = floatstr(tmpstring);
    case 8: i[2] = floatstr(tmpstring);
    case 9: bp = strval(tmpstring);
    case 10: v = strval(tmpstring);
    case 11: lp = strval(tmpstring);
    case 12: ond = strval(tmpstring);
    }
    oldi=i;
    }
    }
    ^ Das anstatt sscanf. Ist zwar mehr Code, dafür tut es aber, und zwar IMMER!

  • Klaro. Also, als erstes Zeichen setzen wir ein "|", damit der Code weiß, wo er anfangen soll. Dann geht der Code Zeichen für Zeichen durch den string, der ja "result" heißt. Jedes mal, wenn ein "|" gefunden wird, dann wird "result" zwischengespeichert in "tmpstring" und praktisch zerschnitten, und zwar vom letzten gefundenen "|" bis zum eben gefundenen "|". Das wird dann (je nach Findungsnummer) in die jeweilige Variable gespeichert.
    Bsp:


    Code
    |kjs|test|dfdfdf|
    0123456789


    Nehmen wir "test". (Im switch wäre das CASE 2 [ist ja das zweite Element]).


    => Zuletzt gefunden den "|" an der Stelle 4.
    => Jetzt gefunden, den "|" an der Stelle 9.


    => tmpstring wird von 0 bis 4+1 (=5) abgeschnitten, und von 8 bis Ende.
    => es bleibt "test" in tmpstring übrig.


    Prinzip verstanden?

  • Okay, danke für die Erklärung. Habe ich nun mehr oder weniger verstanden.


    Nur noch eine Frage, wo genau muss ich dass dann mit "Tanke[t][iconx]" etc einfügen?
    Muss ja noch innerhalb der for schleife sein, weil die Variable ja dort erstellt wurde.


    Wäre es so richtig?
    strins(result, "|", strlen(result));
    new oldi=0;
    new count=0;
    for(new t=0; t<strlen(result); t++)
    {
    if(result[t]=='|')
    {
    count++;
    new tmpstring[sizeof(result)]; tmpstring=result;
    strdel(tmpstring, t, strlen(tmpstring));
    strdel(tmpstring, 0, oldi+1);
    switch(count)
    {
    case 1: ttid = strval(tmpstring);
    case 2: format(ow, sizeof(ow), "%s", tmpstring);
    case 3: pos[0] = floatstr(tmpstring);
    case 4: pos[1] = floatstr(tmpstring);
    case 5: pos[2] = floatstr(tmpstring);
    case 6: i[0] = floatstr(tmpstring);
    case 7: i[1] = floatstr(tmpstring);
    case 8: i[2] = floatstr(tmpstring);
    case 9: bp = strval(tmpstring);
    case 10: v = strval(tmpstring);
    case 11: lp = strval(tmpstring);
    case 12: ond = strval(tmpstring);
    }
    printf(" Loops : %i", t);
    CreatePickup(1274,1,pos[0],pos[1],pos[2]);
    oldi=t;
    }


    }

  • Nein. Du ersetzt einfach die sscanf Zeile (nur die eine Zeile) mit dem Code von mir.
    Darunter hast du ja dann die:
    Tanke[idx][ky] = i[1];//


    Das wäre die einfachste Methode, ohne dass du viel am Code machen musst.
    Ansonsten kannst du natürlich die Variablen direkt hinter die Case's stellen. Beachte aber, dass "t" der Buchstabe ist, idx solltest du weiterhin behalten.


    Wie gesagt, die sscanf Zeile mit dem von mir ersetzen, denn der Code macht 1:1 (nur dass er tut) das Gleiche wie sscanf.

  • Kk


    Habe nun
    new result[500],idx;
    format(result, 128, "SELECT * FROM tankstellen"); //owner = so wie owner eben in der DB heißt
    print(result);
    new ttid,ow[MAX_PLAYER_NAME],Float:pos[3],Float:i[3],bp,v,lp,ond;
    mysql_query(result);
    mysql_store_result();
    //new string[256];
    while(mysql_fetch_row_format(result, "|"))
    {
    print(result);
    strins(result, "|", strlen(result));
    new oldi=0;
    new count=0;
    for(new t=0; t<strlen(result); t++)
    {
    if(result[t]=='|')
    {
    count++;
    new tmpstring[sizeof(result)]; tmpstring=result;
    strdel(tmpstring, t, strlen(tmpstring));
    strdel(tmpstring, 0, oldi+1);
    switch(count)
    {
    case 1: ttid = strval(tmpstring);
    case 2: format(ow, sizeof(ow), "%s", tmpstring);
    case 3: pos[0] = floatstr(tmpstring);
    case 4: pos[1] = floatstr(tmpstring);
    case 5: pos[2] = floatstr(tmpstring);
    case 6: i[0] = floatstr(tmpstring);
    case 7: i[1] = floatstr(tmpstring);
    case 8: i[2] = floatstr(tmpstring);
    case 9: bp = strval(tmpstring);
    case 10: v = strval(tmpstring);
    case 11: lp = strval(tmpstring);
    case 12: ond = strval(tmpstring);
    }
    oldi=t;
    }
    }
    Tanke[idx][id] = ttid;
    Tanke[idx][owner] = ow;
    Tanke[idx][buypreis] = bp;
    Tanke[idx][iconx] = pos[0];
    Tanke[idx][icony] = pos[1];
    Tanke[idx][iconz] = pos[2];
    Tanke[idx][kx] = i[0];
    Tanke[idx][ky] = i[1];
    Tanke[idx][kz] = i[2];
    CreatePickup(1272,1,Tanke[idx][iconx],Tanke[idx][icony],Tanke[idx][iconz],0);


    printf(" %f ", pos[0]);

    idx++;
    }
    return 1;


    Als print gibt er mir allerdings wieder 0.0000 aus

  • Hier mal ein Ausschnitt aus meiner Debug Datei

    SQL
    [01:11:20] CMySQLHandler::Query(SELECT * FROM tankstellen) - Successfully executed.[01:11:20] >> mysql_store_result( Connection handle: 1 )[01:11:20] CMySQLHandler::StoreResult() - Result was stored.[01:11:20] >> mysql_fetch_row_format( Connection handle: 1 )[01:11:20] CMySQLHandler::FetchRow() - Return: 2|0|Niemand|1961.75|1343.11|15.3746|0|0|0|25000|0|0|0[01:11:20] >> mysql_fetch_row_format( Connection handle: 1 )


    Hier mal meine geprinteten results

    SQL
    2|0|Niemand|1961.75|1343.11|15.3746|0|0|0|25000|0|0|0       result1[01:12:52] 2|0|Niemand|1961.75|1343.11|15.3746|0|0|0|25000|0|0|0|         result2[01:12:52]  0.000000 <-Float via pos[0]


    Wo ich die Prints eingefügt habe
    Spoiler anzeigen
    stock LoadTankstellen()
    {

    Spoiler anzeigen
    new result[500],idx;
    format(result, 128, "SELECT * FROM tankstellen");
    print(result);
    new ttid,ow[MAX_PLAYER_NAME],Float:pos[3],Float:i[3],bp,v,lp,ond;
    mysql_query(result);
    mysql_store_result();
    //new string[256];
    while(mysql_fetch_row_format(result, "|"))
    {
    print(result);
    strins(result, "|", strlen(result));
    new oldi=0;
    new count=0;
    for(new t=0; t<strlen(result); t++)
    {
    if(result[t]=='|')
    {
    count++;
    new tmpstring[sizeof(result)]; tmpstring=result;
    strdel(tmpstring, t, strlen(tmpstring));
    strdel(tmpstring, 0, oldi+1);

    switch(count)
    {
    case 1: ttid = strval(tmpstring);
    case 2: format(ow, sizeof(ow), "%s", tmpstring);
    case 3: pos[0] = floatstr(tmpstring);
    case 4: pos[1] = floatstr(tmpstring);
    case 5: pos[2] = floatstr(tmpstring);
    case 6: i[0] = floatstr(tmpstring);
    case 7: i[1] = floatstr(tmpstring);
    case 8: i[2] = floatstr(tmpstring);
    case 9: bp = strval(tmpstring);
    case 10: v = strval(tmpstring);
    case 11: lp = strval(tmpstring);
    case 12: ond = strval(tmpstring);

    }

    oldi=t;
    }

    }
    print(result);
    Tanke[idx][id] = ttid;
    Tanke[idx][owner] = ow;
    Tanke[idx][buypreis] = bp;
    Tanke[idx][iconx] = pos[0];
    Tanke[idx][icony] = pos[1];
    Tanke[idx][iconz] = pos[2];
    Tanke[idx][kx] = i[0];
    Tanke[idx][ky] = i[1];
    Tanke[idx][kz] = i[2];
    CreatePickup(1272,1,Tanke[idx][iconx],Tanke[idx][icony],Tanke[idx][iconz],0);

    Spoiler anzeigen
    printf(" %f ", pos[0]);

    idx++;
    }
    return 1;
    }



  • Dein Problem besteht darin jetzt mal bezogen auch auf sscanf das deine splitabfolge nicht richtig ist
    2|0|Niemand|1961.75|1343.11|15.3746|0|0|0|25000|0|0|0


    nur ist das etwas blöd dies richtig zu stellen da ich leider den aufbau dieser tabelle nicht kenne ebenso wie das enum welches du als index nutzt für das array Tanke.
    wenn spalten die selbe reihenfolge haben wie deine abfolge im enum wäre das nicht schlecht dann kannst du das problem mit sscanf ganz einfach beseitigen und das ganze auch nochmal vereinfacht umsetzen.

  • Hatte es ja vorher mit sscanf, allerdings war der float ebenfalls 0.0000


    enum Tankstelleninfo
    {
    id,
    owner[MAX_PLAYER_NAME],
    Float:iconx,
    Float:icony,
    Float:iconz,
    Float:kx,
    Float:ky,
    Float:kz,
    literpreis,
    buypreis,
    vorrat,
    owned
    }
    new Tanke[MAX_TANKE][Tankstelleninfo];


    Einmal editiert, zuletzt von Decoder ()

  • Hatte es ja vorher mit sscanf, allerdings war der float ebenfalls 0.0000


    Das lag an deiner abfolge der specifer so sollte es gehen falls nix ausgegeben wird könnte das noch zusätzlich daran liegen das du die funktion sscanf in deinem skript enthalten hast.




    stock LoadTankstellen()
    {
    new idx,result[128],string[64];
    mysql_query("SELECT * FROM tankstellen;");
    mysql_store_result();
    while(mysql_fetch_row_format(result, "|")){
    sscanf(result, "p<|>e<i{i}s[24]ffffffiiii>",Tanke[i]);
    CreatePickup(1274,1,Tanke[idx][iconx],Tanke[idx][icony],Tanke[idx][iconz],0);
    if(!Tanke[idx][owned])format(string,64,"Tanke %i\nKaufpreis %i", Tanke[idx][id], Tanke[idx][buypreis]);
    else format(string,64,"Tanke %i\nBesitzer %s\nLiterpreis %i\n %i /1000l",Tanke[idx][id],Tanke[idx][owner],Tanke[idx][literpreis],Tanke[idx][vorrat]);
    Create3DTextLabel(string,0xFFFFFFFF,Tanke[idx][iconx],Tanke[idx][icony],Tanke[idx][iconz],30,0,0);
    ++idx;
    }
    printf(" >> %i Tankstellen geladen!", idx);
    return mysql_free_result();
    }