SA-MP Forums Archive
Split function problem. - 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: Split function problem. (/showthread.php?tid=432774)



Split function problem. - Roel - 24.04.2013

Hello,

I have to following code, and for some reason it doesn't print me step12, which means that the code stops running at the split function;

pawn Код:
new m_attach[13][16];
    print("step11");
    print(data[3]);
    split(data[3], m_attach, ',');
    print("step12");
    if(strval(m_attach[11]) != 0)
    {
        print("step13");
        SetPlayerAttachedObject(playerid, 0, strval(m_attach[0]), strval(m_attach[1]), floatstr(m_attach[2]), floatstr(m_attach[3]), floatstr(m_attach[4]), floatstr(m_attach[5]), floatstr(m_attach[6]), floatstr(m_attach[7]), floatstr(m_attach[8]), floatstr(m_attach[9]), floatstr(m_attach[10]), strval(m_attach[11]), strval(m_attach[12]));
    }
    else
    {
        print("step14");
        SetPlayerAttachedObject(playerid, 0, strval(m_attach[0]), strval(m_attach[1]), floatstr(m_attach[2]), floatstr(m_attach[3]), floatstr(m_attach[4]), floatstr(m_attach[5]), floatstr(m_attach[6]), floatstr(m_attach[7]), floatstr(m_attach[8]), floatstr(m_attach[9]), floatstr(m_attach[10]));
    }
    pGeneral[playerid][PLR_ATTACHED_ID] = strval(data[0]);
    print("step4");
data[3] contains: 19137, 2, 0.138999, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000,0,0,


Re: Split function problem. - MP2 - 24.04.2013

Use sscanf.


Re: Split function problem. - Ballu Miaa - 24.04.2013

Quote:
Originally Posted by MP2
Посмотреть сообщение
Use sscanf.
Do what MP2 said. Use sscanf or show us your split function , maybe we can fix it by updating something in the code.


Re: Split function problem. - Roel - 25.04.2013

Ye well I fixed it, it seems the stringsize of data was to small, something that happends to me often ;p
Anyway I prefer using split because now i don't have to create many different variables like ints,floats,strings.
But anyway, thanks.


Re: Split function problem. - iggy1 - 25.04.2013

If your still going to use the same split function you might want to edit it, so that it doesn't break your code when an incorrect array size is used. EG, send the size of the string with the function call. Make it give a warning instead of crashing.