For loop, help.
#1

Hello!

I'm trying to make a loop using my MySQL data. I have 5 columns, called A1, A2, A3, A4 and A5.

I don't know how I can do, for example (the code is my idea, don't work):

Код:
new id = GetPlayerVehicleID(playerid);
new string[240];
for (new i = 1; i < 6; i++)
{
     format(string, sizeof(string), "%sItem ID Stored on DB: %d", string,  Vehicle[id]["A"+1];
}
ShowPlayerDialog(playerid, DIALOG_TRUNK, DIALOG_STYLE_LIST, "Trunk", string, "Change", "Exit");
Obviously, Vehicle[id]["A"+i] should't work. Anyone know how I can make it? Thanks!
Reply
#2

Change "Vehicle[id]["A"+1]" for "Vehicle[id][WHATEVER_YOUR_ENUMERATOR_IS_CALLED:i]"

Note the text in red (you have to replace it).

By the way, that way of formatting + appending is very slow. Use format in combination of strcat.
Reply
#3

The ENUM has 10 variables, it will be confusing i think...

Here it is:

Код:
enum VehicleTrunk
{
        A1,
	A2,
	A3,
	A4,
	A5,
	M1,
	M2,
	M3,
	M4,
	M5
}
Reply
#4

Vehicle[id][VehicleTrunk:i]

Since the elements are consecutively placed, there won't be any problems. Just loop from 0 to 4.

By the way, you're missing a closing parentheses after Vehicle[id]["A"+1].
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)