SA-MP Forums Archive
For loop, help. - 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: For loop, help. (/showthread.php?tid=618630)



For loop, help. - HidroDF - 08.10.2016

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!


Re: For loop, help. - SickAttack - 08.10.2016

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.


Respuesta: For loop, help. - HidroDF - 08.10.2016

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
}



Re: For loop, help. - SickAttack - 08.10.2016

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].