Help with converting this (?)
#1

Can someone tell me how can I use ternary operators for this code? I tried but ended up with errors lol.

PHP код:
if (_house_HasVehicles(houseid))
{
    for (new 
0MAX_PLAYER_VEHICLESji++)
    {
        if (
g_HouseData[houseid][h_pVehs][i])
        {
            
idx vehicle_ReturnIndex(GetVehicleModel(g_HouseData[houseid][h_pVehs][i]));
            if (
g_VehicleData[g_HouseData[houseid][h_pVehs][i]][v_Parked])
                
format(list, sizeof(list), "%s%s\tParked\n", list, g_DealerCars[idx][car_Name]);
            else
                
format(list, sizeof(list), "%s%s\tUnparked\n", list, g_DealerCars[idx][car_Name]);
        }
        else
            
format(list, sizeof(list), "%sEmpty\n", list);
    }
    
format(list, sizeof(list), "Vehicle\tStatus\n%s", list);
    
ShowPlayerDialog(playeridD_UNPARKEDVEHICLESDIALOG_STYLE_TABLIST_HEADERS"Your vehicles", list, "Select""Back");

Or if it's not possible, then are there any better ways to format this list? This right now just works fine but I am just looking for other ways if there's any. Which is probably better than this.
Reply
#2

I think you can also do the middle one, but then again I'm not great with ternary operators.
Код:
format(list, sizeof(list), "%s%s\t%s\n", list, g_DealerCars[idx][car_Name], (g_VehicleData[g_HouseData[houseid][h_pVehs][i]][v_Parked] > 0) ? ("Parked") : ("Unparked"));
Reply
#3

Alright, that just gave me a new idea, thanks.

But apart from ternary operator, is there any other way I can format huge lists like this for dialogs? Cause I saw a post someone writing before that this method is inefficient.
Reply
#4

car_Name is probably a string.
If it is, I guess you can use strcat.

Код:
strcat(list, g_DealerCars[idx][car_Name]);
strcat(list, "\tParked\n");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)