Embedded colours
#1

Hi. I want to use embedded colours in my dialog but in a different way. I know how to use them etc, I want to use them like this.

Example:
I have a dialog which is looped in an array for example, teleports and I want to do this,
Teleport 1
Teleport 2
Teleport 3
Teleport 4

And that keeps going until the loop ends.

Thanks.
Reply
#2

Simply create a variable before the loop:

pawn Код:
new ColorOption;
Then you switch between 1 and 0 each loop:

pawn Код:
for(......)
{
if(ColorOption == 0)
{
ColorOption = 1;
//code for red color
}
else
{
ColorOption = 0
//code for green color
}
}
I hope you understand what I mean.
Reply
#3

for(i=0;i<Max;i++)
if(i%2==0)RED
else GREEN

Hope this helps you
Reply
#4

I know there is a simpler yet efficient way of doing it. Thanks though.

This is what my code looks like.
pawn Код:
stock GetTeles(playerid) {
    new string[1000];
    for(new i = 0; i < sizeof(TeleportsPos); i++) {
        format(string, sizeof string, "%s%s\n", string, TeleportsPos[i][Name]);
    }
    ShowPlayerDialog(playerid, DIALOG_TELES, DIALOG_STYLE_LIST, "Teleports", string, "Teleport", "Cancel");
    return 1;
}
Reply
#5

This is the most optimased I can think of:
pawn Код:
stock GetTeles(playerid) {
    new string[1000];
    for(new i = 0; i < sizeof(TeleportsPos); i++) {
        format(string, sizeof string, "%s%s%s\n", string,(i%2)?("{FF0000}"):("{00FF00}"), TeleportsPos[i][Name]);
    }
    ShowPlayerDialog(playerid, DIALOG_TELES, DIALOG_STYLE_LIST, "Teleports", string, "Teleport", "Cancel");
    return 1;
}
Reply
#6

Mod is slow though. Bitwise and is much faster.

pawn Код:
format(string, sizeof string, "%s%s%s\n", string, (i & 1) ? ("{FF0000}") : ("{00FF00}"), TeleportsPos[i][Name]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)