Phone system - variables being overwritten.
#1

Code:

Код:
case DIALOG_PHONE_TEXT_NUMBER_INPUT:
		{
		    if (response)
		    {
		        new number = SMSPerson[playerid], target;
		        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_PHONE_TEXT_NUMBER_INPUT, DIALOG_STYLE_INPUT, "Phone - Text", "Write down the message:", "Select", "Cancel");
		    
		        foreach(Player, i)
				{
				    printf("Foreach: %d %d %d", CharacterData[i][pLoggedIn], CharacterData[i][pPhoneNumber], number);
				    if (CharacterData[i][pLoggedIn] && CharacterData[i][pPhoneNumber] == number)
					{
				    	target = i;
				    	break;
				    }
				    else return ErrorMessage(playerid, "You have entered an invalid number!");
				}
				new slot = -1;
				
				for (new t = 1; t < MAX_STORED_TEXTS; t ++)
				{
				    if (!PhoneMessage[target][phone_text_Taken][t])
				    {
				        slot = t;
						break;
				    }
				}
				
				PhoneMessage[target][phone_text_Taken][slot] = 1;
				format(PhoneMessage[target][phone_Messages][slot], 128, "%s", inputtext);
				format(PhoneMessage[target][phone_text_Sender][slot], 25, "%s", PlayerRPName(playerid));
				format(PhoneMessage[target][phone_text_Reciever][slot], 25, "%s", PlayerRPName(target));

				if (slot == -1) return ErrorMessage(playerid, "That player's inbox is full!");
				if (PhoneOnline[target]) return ErrorMessage(playerid, "That player's phone is offline!");

				TextLog(inputtext);
				PlayerPlaySound(target, 1052, 0.0, 0.0, 0.0);
				PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);

				PhoneData[target][phone_TotalMessage] ++;
				
				printf("Creating a SMS on slot id %i", slot);
				for (new t = 1; t < MAX_STORED_TEXTS; t ++)
				{
				    printf("%d) %s | %s | %s | %d | %d", t, PhoneMessage[target][phone_Messages][t], PhoneMessage[target][phone_text_Sender][t], PhoneMessage[target][phone_text_Reciever][t],PhoneMessage[target][phone_text_Taken][t], t);
				}
				return 1;
   			}
		    else
		    {
		        ShowPlayerDialog(playerid, DIALOG_PHONE, DIALOG_STYLE_LIST, "Phone", "Contacts\nCall\nText", "Select", "Close");
		    }
		}
This piece of code has two failures, one is that the Foreach loop only checks ID 0:

Код:
[22:40:07] Foreach: 1 8376 5793 // 
[22:40:30] Foreach: 1 8376 5793 //
The foreach code is only called once but if there are two players it should debug twice.

The second bug is a bug with saving the variables:

This is the debug that you can find in the code above, it should only change the first one not all of them, and look how by each step it loses a character?
Код:
[22:37:21] 1) Jihad | Jihad Warrior | Jihad Warrior  | 1 | 1
[22:37:21] 2) ihad | ihad Warrior  | ihad Warrior | 0 | 2
[22:37:21] 3) had | had Warrior  | had Warrior  | 0 | 3
[22:37:21] 4) ad | ad Warrior  | ad Warrior  | 0 | 4
[22:37:21] 5) d | d Warrior  | d Warrior | 0 | 5
[22:37:21] 6)  |  Warrior |  Warrior | 0 | 6
[22:37:21] 7)  | Warrior | Warrior | 0 | 7
[22:37:21] 8)  | arrior  | arrior | 0 | 8
[22:37:21] 9)  | ice | ice | 0 | 9
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)