SA-MP Forums Archive
\n problem. Dynamic Updates - 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: \n problem. Dynamic Updates (/showthread.php?tid=664170)



\n problem. Dynamic Updates - Score - 20.02.2019

Hello, so I have made a new "dynamic update system", which means I can add and or edit updates while being in-game. But, there is an "issue" I would call it.

It looks like this:



But I want it to look like this, you know have a \n where the white lines are. Only want to split the line for each status.

Here's how I want it to look:




I want to split the text at the white lines, here's the code I currently have:

pawn Код:
forward OnPlayerViewUpdates(playerid);
public OnPlayerViewUpdates(playerid)
{
    if(cache_num_rows())
    {
        new string[300];
        format(string, sizeof(string), "{FFFFFF}Server Last Updates:\n\n");
        for(new i = 0; i < cache_num_rows(); i ++)
        {
            new text[128], addedby[24], status, prevStatus = 0;
            cache_get_value_name(i, "AddedBy", addedby);
            cache_get_value_name(i, "Text", text);
            cache_get_value_name_int(i, "Status", status);
           
            switch(status)
            {
                case 1:
                {
                    format(string, sizeof(string), "%s{AFAFAF}{1766AA}added{AFAFAF}\t\t%s\t [%s]\n", string, text, addedby);
                    if(prevStatus != status)
                    {
                        strcat(string, "\n");
                        prevStatus = status;
                    }
                }
                case 2:
                {
                    format(string, sizeof(string), "%s{AFAFAF}{4D4747}fixed{AFAFAF}\t\t%s\t [%s]\n", string, text, addedby);
                    if(prevStatus != status)
                    {
                        strcat(string, "\n");
                        prevStatus = status;
                    }
                }
                case 3:
                {
                    format(string, sizeof(string), "%s{AFAFAF}{E42626}removed{AFAFAF}\t\t%s\t [%s]\n", string, text, addedby);
                    if(prevStatus != status)
                    {
                        strcat(string, "\n");
                        prevStatus = status;
                    }
                }
            }
        }
        Dialog_Show(playerid, DIALOG_UPADDED, DIALOG_STYLE_MSGBOX, "Latest Updates", string, "OK", "");



Re: \n problem. Dynamic Updates - Nero_3D - 21.02.2019

You are recreating the prevStatus variable inside the loop, therefore it is always 0, create it outside / before the loop
Additionally you can move your "if(prevStatus != status)" statement after the switch because it is the same code in all cases