PDA

View Full Version : estimated max. usage: unknown, due to recursion


Lirbo
15/04/2016, 08:44 PM
Header size: 10432 bytes
Code size: 1084596 bytes
Data size: 21742740 bytes
Stack/heap size: 16384 bytes; estimated max. usage: unknown, due to recursion
Total requirements:22854152 bytes

I got this when I complied, could anyone explain me what does it mean?

it happened after I placed the next command:

CMD:dice(playerid,params[]){
LoggedCMD
if(!IsPlayerInRangeOfPoint(playerid,2,214.6529,182 8.4265,2001.0857)) return MSG(playerid,C_RED,"[Error] {ff9999}You're not in the right place to use this command.");
if(sscanf(params,"sd",MiniString,param[0])) return MSG(playerid,C_RED,"[Error] {FF9999}/Dice [1-6/Even/Odd] [Amount]");
if(param[0]>DB[playerid][Money] || param[0]<1) return MSG(playerid,C_RED,"[Error] {Ff9999}Invalid Amount.");
if(strcmp(MiniString,"1",true) && strcmp(MiniString,"2",true) && strcmp(MiniString,"3",true) && strcmp(MiniString,"4",true) && strcmp(MiniString,"5",true) && strcmp(MiniString,"6",true) && strcmp(MiniString,"Even",true) && strcmp(MiniString,"Odd",true)) return MSG(playerid,C_RED,"[Error] {ff9999]/Dice [1-6/Even/Odd]");
new PlayerBet[MAX_PLAYERS],DiceResult[MAX_PLAYERS],bool:WonX2[MAX_PLAYERS],bool:WonX6[MAX_PLAYERS];

if(!strcmp(MiniString,"1",true)){PlayerBet[playerid] = 1;}
if(!strcmp(MiniString,"2",true)){PlayerBet[playerid] = 2;}
if(!strcmp(MiniString,"3",true)){PlayerBet[playerid] = 3;}
if(!strcmp(MiniString,"4",true)){PlayerBet[playerid] = 4;}
if(!strcmp(MiniString,"5",true)){PlayerBet[playerid] = 5;}
if(!strcmp(MiniString,"6",true)){PlayerBet[playerid] = 6;}
if(!strcmp(MiniString,"Even",true)){PlayerBet[playerid] = 7;}
if(!strcmp(MiniString,"Odd",true)){PlayerBet[playerid] = 8;}

new rand = random(2);
switch(rand){
case 0: DiceResult[playerid] = 1;
case 1: DiceResult[playerid] = 2;
case 2: DiceResult[playerid] = 3;
case 3: DiceResult[playerid] = 4;
case 4: DiceResult[playerid] = 5;
case 5: DiceResult[playerid] = 6;
case 6: DiceResult[playerid] = 7;
case 7: DiceResult[playerid] = 8;}

if(PlayerBet[playerid] == 1 && DiceResult[playerid] == 1){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 2 && DiceResult[playerid] == 2){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 3 && DiceResult[playerid] == 3){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 4 && DiceResult[playerid] == 4){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 5 && DiceResult[playerid] == 5){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 6 && DiceResult[playerid] == 6){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 7 && DiceResult[playerid] == 2 || DiceResult[playerid] == 4 || DiceResult[playerid] == 6){WonX2[playerid] = true;} else{WonX2[playerid] = false;}
if(PlayerBet[playerid] == 8 && DiceResult[playerid] == 1 || DiceResult[playerid] == 3 || DiceResult[playerid] == 5){WonX2[playerid] = true;} else{WonX2[playerid] = false;}

if(WonX2[playerid] && !WonX6[playerid]){
format(SString,sizeof(SString),"[Casino] {00FF00}YOU WON $%s!",Comma(param[0]*2));
MSG(playerid,C_GOLD,SString);
DB[playerid][Money]=DB[playerid][Money]+param[0];
WonX2[playerid] = false;
WonX6[playerid] = false;}

if(!WonX2[playerid] && WonX6[playerid]){
format(SString,sizeof(SString),"[Casino] {00FF00}YOU WON $%s!",Comma(param[0]*6));
MSG(playerid,C_GOLD,SString);
DB[playerid][Money]=DB[playerid][Money]+param[0]*5;
WonX2[playerid] = false;
WonX6[playerid] = false;}

if(!WonX2[playerid] && !WonX6[playerid]){
format(SString,sizeof(SString),"[Casino] {FF0000}You didn't win this this time.",Comma(param[0]*6));
MSG(playerid,C_GOLD,SString);
DB[playerid][Money]=DB[playerid][Money]+param[0]*5;
WonX2[playerid] = false;
WonX6[playerid] = false;}

if(WonX2[playerid] && WonX6[playerid]){
MSG(playerid,C_GOLD,"[Casino] {FF0000}If you see this message contact the admins as soon as possible.");
WonX2[playerid] = false;
WonX6[playerid] = false;
return 1;}

BloodyRP
15/04/2016, 08:46 PM
Think u will not understand what I say in english, but: that means that u have tooo much size used.
Like: string[500]; everywhere. too much variables with huge size.
U can also set
#pragma dynamic 3000
or more, if needed.
(Hope someone else will say for u normally, but maybe u understand somethink :D)

and u dont need to use ministring there. u have params[] by default from DC_CMD/ZCMD or what u have. just put params[0],params[1],params[2] and etc if u want that.

Vince
15/04/2016, 09:38 PM
This may not have anything to do with it, but haven't you noticed how extremely repetitive your code is?


switch(rand){
case 0: DiceResult[playerid] = 1;
case 1: DiceResult[playerid] = 2;
case 2: DiceResult[playerid] = 3;
case 3: DiceResult[playerid] = 4;
case 4: DiceResult[playerid] = 5;
case 5: DiceResult[playerid] = 6;
case 6: DiceResult[playerid] = 7;
case 7: DiceResult[playerid] = 8;}

versus

DiceResult[playerid] = rand + 1;

and

if(PlayerBet[playerid] == 1 && DiceResult[playerid] == 1){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 2 && DiceResult[playerid] == 2){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 3 && DiceResult[playerid] == 3){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 4 && DiceResult[playerid] == 4){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 5 && DiceResult[playerid] == 5){WonX6[playerid] = true;} else{WonX6[playerid] = false;}
if(PlayerBet[playerid] == 6 && DiceResult[playerid] == 6){WonX6[playerid] = true;} else{WonX6[playerid] = false;}

versus

WonX6[playerid] = (PlayerBet[playerid] == DiceResult[playerid]);

NaS
15/04/2016, 10:10 PM
Your code looks terrible!

"estimated max. usage: unknown, due to recursion"

The warning is no problem at all.

Just means the Compiler cannot tell what the max. size of the heap/stack is because some code runs in recursion.
Recursion means if a function calls itself, all containing variables are initialized again, however the Compiler does not know how often this happens because it's decided run-time.

I don't see a recursion in your code though. Is MiniString global?

Lirbo
16/04/2016, 07:38 AM
Your code looks terrible!

"estimated max. usage: unknown, due to recursion"

The warning is no problem at all.

Just means the Compiler cannot tell what the max. size of the heap/stack is because some code runs in recursion.
Recursion means if a function calls itself, all containing variables are initialized again, however the Compiler does not know how often this happens because it's decided run-time.

I don't see a recursion in your code though. Is MiniString global?

MiniString appears on the top of the script.
I changed the WHOLE fucking code now and deleted the strings from the top of the script and moved them into the functions itself with approximate bytes size of the string but sadly I think it's even worse. What would be better? to put it up there or create the "new String[X]" again and again?

NaS
16/04/2016, 08:07 AM
As I said, it's not a problem that it shows that message when compiling unless your script doesn't run at all.

However you should put "new MiniString[X];" into your command (and other functions/callbacks where you use it). It will make it a tiny bit faster and it's commonly done that way.

Lirbo
16/04/2016, 08:11 AM
Your code looks terrible!

"estimated max. usage: unknown, due to recursion"

The warning is no problem at all.

Just means the Compiler cannot tell what the max. size of the heap/stack is because some code runs in recursion.
Recursion means if a function calls itself, all containing variables are initialized again, however the Compiler does not know how often this happens because it's decided run-time.

I don't see a recursion in your code though. Is MiniString global?

As I said, it's not a problem that it shows that message when compiling unless your script doesn't run at all.

However you should put "new MiniString[X];" into your command (and other functions/callbacks where you use it). It will make it a tiny bit faster and it's commonly done that way.


You earned your rep!
btw I tried to expand it by 10000 by now it shows it again xD how much should I expand?

NaS
16/04/2016, 08:27 AM
You earned your rep!
btw I tried to expand it by 10000 by now it shows it again xD how much should I expand?

What do you mean? Are you talking about "#pragma dynamic" I took out of my reply?
If yes, you don't need to, it doesn't have anything to do with it. I was mixing it up with another compiler warning :/

If you have big ass local arrays somewhere (4096 slots or more, which is the default heap/stack size) you should use dynamic to extend the stack/heap, otherwise it's pointless.

introzen
16/04/2016, 10:32 AM
WonX6[playerid] = (PlayerBet[playerid] == DiceResult[playerid]);


Stealing the thread for my own education.

What's the difference in writing this?

WonX6[playerid] = (PlayerBet[playerid] == DiceResult[playerid]) ? (true) : (false);

Konstantinos
16/04/2016, 10:36 AM
Both do the same thing but using parenthesis makes it a statement that can be only true or false. Ternary operator in that case is not needed.

introzen
16/04/2016, 10:38 AM
Both do the same thing but using parenthesis makes it a statement that can be only true or false. Ternary operator in that case is not needed.

so
WonX6[playerid] = (PlayerBet[playerid] == DiceResult[playerid]);
Will set WonX6[playerid] = 7 assuming both PlayerBet[playerid] and DiceResult[playerid] are 7?

NaS
16/04/2016, 10:41 AM
so
WonX6[playerid] = (PlayerBet[playerid] == DiceResult[playerid]);
Will set WonX6[playerid] = 7 assuming both PlayerBet[playerid] and DiceResult[playerid] are 7?

It will set WonX6 to true or false, depending on if PlayerBet and DiceResult are the same (value doesnt matter).
You can think of this as in an if() statement, if works with true/false condition, so you basically apply that condition to a variable.

Konstantinos
16/04/2016, 10:42 AM
No.

If PlayerBet[playerid] and DiceResult[playerid] are 7 then Won6[playerid] will be true.
If PlayerBet[playerid] and DiceResult[playerid] are not 7 then Won6[playerid] will be false.

introzen
16/04/2016, 10:48 AM
It will set WonX6 to true or false, depending on if PlayerBet and DiceResult are the same (value doesnt matter).
You can think of this as in an if() statement, if works with true/false condition, so you basically apply that condition to a variable.

No.

If PlayerBet[playerid] and DiceResult[playerid] are 7 then Won6[playerid] will be true.
If PlayerBet[playerid] and DiceResult[playerid] are not 7 then Won6[playerid] will be false.

Thank you!