Getting two random numbers and putting them together into a variable.
#1

Код:
	if(strcmp(cmd, "/vrn", true) == 0)
	{
		new VR1 = random(sizeof(vehreglet));
		new VR2 = random(sizeof(vehregnum));
		new VRF[256];
		format(VRF, sizeof(VRF), "%s%s%s%s%s%s%s%s%s",vehreglet[VR1][0],vehregnum[VR2][0],vehreglet[VR1][1],vehregnum[VR2][1],vehreglet[VR1][2],vehregnum[VR2][2],vehreglet[VR1][3],vehregnum[VR2][3],vehreglet[VR1][4]);
		MYVARIABLE = VRF;
		new string[256];
		format(string, sizeof(string), "%s", MYVARIABLE);
		SendClientMessage(playerid, COLOR_YELLOW, string);
		return 1;
	}
VR1 is getting a random array from vehreglet.
VR2 is getting a random array from vehregnum.

Let's say VR1 gets the letter h and VR2 lets the number 9. I want to put those together so they form "h9". And store that in MYVARIABLE. I wanna do this so later I could store it in SQL. Any ideas?
Reply
#2

format(something, sizeof(something), "%s%d", VR1, VR2);

replace something with the desired variable
Reply
#3

That's a problem because my variable doesn't work like that. If I set MYVARIABLE = SOMETHING, it says, "Array must be indexed." No idea how to work this.
Reply
#4

You can't store a string (Alphanumeric text) in a variable, it must be stored in a string.

Example:

new Variable; - bad

new String[2] - good

You may need to change the 2 to suit your needs..

Errr, looking at the code, why do you even need MYVARIABLE? What's wrong with VHF?
Reply
#5

I want to set MYVARIABLE = to VRF, but if I format MYVARIABLE, it doesn't let me. If I set MYVARIABLE = to VRF, still no good

And again, I need MYVARIABLE for SQL storage.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)