or destination array is too small?
#1

Quote:
Originally Posted by zSuYaNw
Посмотреть сообщение
gerar palavra aleatуria


PHP код:
#define MAX_WORDS                       15
stock GenerateRandomWord(){
    new
        
iKey[MAX_WORDS]
    ;
    for(new 
i!= MAX_WORDS; ++i){
        
iKey[i] = (random('Z'-'A')+'A' random('x'-'a')+'a');
    }
    
    return 
iKey;

So, you got this code but it does not work the correct way why?

Код:
\gamemode SAMP\gamemodes\Roleplay.pwn(3584) : error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
PHP код:
PlayerData[playerid][pIdentidade] = GenerateRandomWord(); //error 
Reply
#2

The array size is not matching the error is self explanatory
assuming it is in enum

Код:
enum yourenum
{
//***
pIdentidade[MAX_WORDS],
//***
}
because the returning string iKey has size MAX_WORDS
Reply
#3

For direct array assignments both arrays must have the same number of dimensions and additionally the array on the left must have a size equal or greater than the array on the right. The first requirement isn't fulfilled so this will never work like that. Use some form of strcpy.
Reply
#4

This business is very annoying for something small, how to solve it ae?

Код:
gamemode SAMP\gamemodes\Roleplay.pwn(62) : error 074: #define pattern must start with an alphabetic character
gamemode SAMP\gamemodes\WR-Roleplay.pwn(165) : error 017: undefined symbol "MAX_WORDS"
gamemode SAMP\gamemodes\Roleplay.pwn(1109) : error 017: undefined symbol "MAX_WORDS"
gamemode SAMP\gamemodes\Roleplay.pwn(1109) : error 009: invalid array size (negative, zero or out of bounds)
gamemode SAMP\gamemodes\Roleplay.pwn(1109) : error 036: empty statement
gamemode SAMP\gamemodes\Roleplay.pwn(1109) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


6 Errors.
PHP код:
stock GenerateRandomWord()
{
    new 
iKey[MAX_WORDS]; //error
    
for(new i!= MAX_WORDS; ++i){
        
iKey[i] = (random('Z'-'A')+'A' random('x'-'a')+'a');
    }
    return 
iKey;
}
PlayerData[playerid][pIdentidade] = GenerateRandomWord(); 
Reply
#5

PHP код:
format(PlayerData[playerid][pIdentidade], 50GenerateRandomWord()); 
Reply
#6

It has been resolved, How do I generate only numbers, from 1 to 9?

@edit

Why is not it working?

PHP код:
stock GenerateRandomWord()
{
    new 
iKey[15];
    for(new 
i!= 15; ++i)
        
iKey[i] = (random('1'-'9')+'A' random('x'-'a')+'a');
    return 
iKey;

Reply
#7

Quote:
Originally Posted by SukMathcuck
Посмотреть сообщение
It has been resolved, How do I generate only numbers, from 1 to 9?

@edit

Why is not it working?

PHP код:
stock GenerateRandomWord()
{
    new 
iKey[15];
    for(new 
i!= 15; ++i)
        
iKey[i] = (random('1'-'9')+'A' random('x'-'a')+'a');
    return 
iKey;

like so: (random(9)+1)

the +1 is there so that if random returns 0 we weon't see that 0 but 1 instead.
possible numbers will be 1,2,...,9


in your case...
PHP код:
stock GenerateRandomWord()
{
    new 
iKey[15];
    for(new 
i!= 15; ++i)
        
iKey[i] = (random('9'-'1')+'1' random('x'-'a')+'a');
    return 
iKey;

Reply
#8

That gets the decimal though, not the character code which he's after. I suggest you add these little wrappers first:
PHP код:
minrandom(minmax)
    return 
random(max min) + min;

isOdd(number)
    return 
number 1// faster than mod 
Then you can easily use these wherever they are needed.

PHP код:
iKey[i] = isOdd(i) ? minrandom('1''9') : minrandom('a''z'); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)