Break; function error
#1

I have this script where the system gives items, and here's how i planned it to work

Код:
- The system searches the inventory for a vacant slot. if found, the player receives level 1 version of the item and its placed on that slot, then it ends the operation.

- If every slot is occupied by level 1 versions of the item, then the system will go to the first slot and "upgrade" that item to a level 2 version, then it ends the operation.

- if every slot is occupied by level 2 versions of the item, then the system will go to the first slot and "upgrade" that item to a level 3 version, then it ends the operation.
I thought I got it, but when I tested it, the break; function doesn't work. It continues to the very last slot.
Reply
#2

Oh shoot, forgot to paste that, sorry.

Pastebin
Reply
#3

why not just use
Код:
PlayerInfo[id][Item][i]++;
and if u want ur highest upgrade to be '3' then put in a if statement and return 1; once it reaches 3 . . .
Reply
#4

Quote:
Originally Posted by Infin1ty
Посмотреть сообщение
why not just use
Код:
PlayerInfo[id][Item][i]++;
and if u want ur highest upgrade to be '3' then put in a if statement and return 1; once it reaches 3 . . .
Something like this?

Pastebin


EDIT: That doesn't work either.
Reply
#5

Код:
for(new i = 0; i < 10; i++)
{
    if(HealthInfo[id][HealthLevel][i] == 3) break;
	else HealthInfo[id][HealthLevel][i]++, break;
}
See if that works for ya. Its much more efficient as well. I've basically done what you did in like 10+ lines but in 4 lines instead.

Another Edit: To the best of my knowledge, I'm not so sure you understand what '++' does, at least according to the second pastebin you sent. This increments the number of 'HealthInfo[id][HealthLevel][i]' up by 1 each time. If you happen to know SQL I'm sure it would remind you of 'AUTO_INCREMENT', it works the same way.
Reply
#6

Quote:
Originally Posted by Infin1ty
Посмотреть сообщение
Код:
for(new i = 0; i < 10; i++)
{
    if(HealthInfo[id][HealthLevel][i] == 3) break;
	else HealthInfo[id][HealthLevel][i]++, break;
}
See if that works for ya. Its much more efficient as well. I've basically done what you did in like 10+ lines but in 4 lines instead.

Another Edit: To the best of my knowledge, I'm not so sure you understand what '++' does, at least according to the second pastebin you sent. This increments the number of 'HealthInfo[id][HealthLevel][i]' up by 1 each time. If you happen to know SQL I'm sure it would remind you of 'AUTO_INCREMENT', it works the same way.
Still doesn't work somehow...
Reply
#7

Show us how you are defining PlayerInfo and the enum inside it aswell
Reply
#8

Quote:
Originally Posted by Shinja
Посмотреть сообщение
Show us how you are defining PlayerInfo and the enum inside it aswell
Код:
enum hInfo
{
	HealthLevel[10]
};
new HealthInfo[MAX_PLAYERS][hInfo];
Reply
#9

Are you sure the variable is working like it suppose to, in that way HealthInfo[id][HealthLevel] might me considered as a string
Reply
#10

Quote:
Originally Posted by Shinja
Посмотреть сообщение
Are you sure the variable is working like it suppose to, in that way HealthInfo[id][HealthLevel] might me considered as a string
It's an array; used it as an array.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)