Questions
#1

Who is code optimization

Код:
stock ShowEvents(playerid)
{
	if(EventID == 0)
	{
	    new string[467], str1[208], str2[217], str3[35];
		format(str1, sizeof(str1), ".......................................");
		format(str2, sizeof(str2), ".......................................");
		format(str3, sizeof(str3), ".......................................");
		format(string, sizeof(string), "%s%s%s", str1, str2, str3);
		ShowPlayerDialog(playerid, 10004, DIALOG_STYLE_LIST, "Events", string, "Ok", "Exit");
	}
	else if(EventID > 0)
	{
	    new string[28];
	    new EventDialog[14] = { 0,10008,10009,10010,10011,10014,10015,10016,10017,10018,10019,10020,10021,10022 };
	    format(string, sizeof(string), "%s", EInfo[EventID][eName]);
		ShowPlayerDialog(playerid, EventDialog[EventID], DIALOG_STYLE_LIST, string, "Open\nClose\nCount", "Ok", "Exit");
	}
	return 1;
}
or

Код:
stock ShowEvents(playerid)
{
	switch(EventID)
	{
		case 0:
		{
		    new string[467], str1[208], str2[217], str3[35];
			format(str1, sizeof(str1), ".......................................");
			format(str2, sizeof(str2), ".......................................");
			format(str3, sizeof(str3), ".......................................");
			format(string, sizeof(string), "%s%s%s", str1, str2, str3);
			ShowPlayerDialog(playerid, 10004, DIALOG_STYLE_LIST, "Events", string, "Ok", "Exit");
		}
		case 1: ShowPlayerDialog(playerid, 10008, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
		case 2: ShowPlayerDialog(playerid, 10009, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
		case 3: ShowPlayerDialog(playerid, 10010, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
		case 4: ShowPlayerDialog(playerid, 10011, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
		case 5: ShowPlayerDialog(playerid, 10014, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
		case 6: ShowPlayerDialog(playerid, 10015, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
		case 7: ShowPlayerDialog(playerid, 10016, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
		case 8: ShowPlayerDialog(playerid, 10017, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
		case 9: ShowPlayerDialog(playerid, 10018, DIALOG_STYLE_LIST, "Events ", "Open\nClose\nCount", "Ok", "Exit");
		case 10: ShowPlayerDialog(playerid, 10019, DIALOG_STYLE_LIST, "Events ", "Open\nClose\nCount", "Ok", "Exit");
		case 11: ShowPlayerDialog(playerid, 10020, DIALOG_STYLE_LIST, "Events ", "Open\nClose\nCount", "Ok", "Exit");
                case 12: ShowPlayerDialog(playerid, 10021, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
                case 13: ShowPlayerDialog(playerid, 10022, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
	}
	return 1;
}
Reply
#2

I am code optimization.

Код:
stock ShowEvents(playerid)
{
	switch(EventID)
	{
		case 0:
		{
		    new string[467], str1[208], str2[217], str3[35];
			format(str1, sizeof(str1), ".......................................");
			format(str2, sizeof(str2), ".......................................");
			format(str3, sizeof(str3), ".......................................");
			format(string, sizeof(string), "%s%s%s", str1, str2, str3);
			ShowPlayerDialog(playerid, 10004, DIALOG_STYLE_LIST, "Events", string, "Ok", "Exit");
		}
		case 1 .. 13: ShowPlayerDialog(playerid, 10007 + EventID, DIALOG_STYLE_LIST, "Events", "Open\nClose\nCount", "Ok", "Exit");
	}
	return 1;
}
But you'll have to make sure every dialog ID match.
If EventID is 4 you'll have 10007 + 4, which is 10011, the dialog you want.
The problem starts after the 5th case, where you have the dialog ID as 10014, not matching. If you're able to modify these dialog ids, i'd recommend you to do it this way.

More than optimization, it's organization.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)