\n problem. Dynamic Updates
#1

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", "");
Reply
#2

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)