SA-MP Forums Archive
Issue with using switch. - 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: Issue with using switch. (/showthread.php?tid=619273)



Issue with using switch. - UnholyBeast - 15.10.2016

After the little bit of help I got last night, I decided to make this stock function to speed up the development process, and this is the issue I am running into with it.

Error the compiler outputs:
Код:
C:\Users\mace\Desktop\Code Related Folders\Untitled Trucking Server\gamemodes\MTruck.pwn(1878) : error 029: invalid expression, assumed zero
The stock function:
Код:
stock ChooseMissionRewardOffJobNumber(playerid)
{
	new string[144], string2[144], reward;
	switch(aTMInfo[][mission_number]) // This is the issue.
	{
		case 0:
		{
			reward = randomEx(950, 1250);
			GivePlayerMoney(playerid, reward);
			format(string, sizeof(string), "%s: Thanks for moving that freight. Good job.", aTMInfo[0][mission_actor_name], reward);
			format(string2, sizeof(string2), "%s(%d) Has moved some frieght for Steve earning a grand total of $%d.", PlayerName(playerid), playerid, reward);
			SendMessage(playerid, -1, string);
			SendMessageToAll(-1, string2);
		}
		case 1:
		{
			reward = randomEx(1000, 1500);
			GivePlayerMoney(playerid, reward);
			format(string, sizeof(string), "%s: You finished just in time. Good job!", aTMInfo[0][mission_actor_name], reward);
			format(string2, sizeof(string2), "%s(%d) has finished working for Ian in Doherty earning a cool $%d.", PlayerName(playerid), playerid, reward);
			SendMessage(playerid, -1, string);
			SendMessageToAll(-1, string2);
		}
	}
	return 1;
}



Re: Issue with using switch. - AndySedeyn - 15.10.2016

You can't leave that empty. It has to access an index for it to be able to switch through a value.

EDIT: 'that' as in the first dimension of the array.


Re: Issue with using switch. - UnholyBeast - 15.10.2016

What would I put in it to use it with switch?


Re: Issue with using switch. - AndySedeyn - 15.10.2016

A reward is given after completing a mission, so I would store the player's missionid in a player variable when the player starts the mission and then use that variable to switch through the different cases.


Re: Issue with using switch. - UnholyBeast - 15.10.2016

Alright. Thank you very much!


Re: Issue with using switch. - GoldenLion - 16.10.2016

Have a look here: https://sampforum.blast.hk/showthread.php?tid=570635
You made a function, not a "stock function".