Empty array
#1

How to check if the integer array is empty without additional variable?
Reply
#2

Well, what values should it handle?

If it can handle every value, then you need a second variable.
Reply
#3

I want to handle every value in array, thanks
Reply
#4

Quote:
Originally Posted by Cyber123
Посмотреть сообщение
How to check if the integer array is empty without additional variable?
An array can never be empty even if all the values are zero as zero is still a value! Your question makes no sense really. Maybe you want to check if integer array is null? All values 0? How the heck is anyone supposed to know?
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
And why do you not want to use additional variables? They aren't expensive.
HAHAAHAHAHAHAHA nice joke
Reply
#6

Quote:
Originally Posted by Pottus
Посмотреть сообщение
An array can never be empty even if all the values are zero as zero is still a value! Your question makes no sense really. Maybe you want to check if integer array is null? All values 0? How the heck is anyone supposed to know?
Yes, I want to check if all values of integer array are 0...

Quote:
Originally Posted by ******
Посмотреть сообщение
And why do you not want to use additional variables? They aren't expensive.
Because i tried with additional variable and can't get what I want.
Reply
#7

PHP код:
#include <a_samp>
#include <streamer>
#include <sscanf2>
#include <ColAndreas>
#include <zcmd>
#include <YSI_Core\y_utils>
#include <YSI_Coding\y_timers>
new Timer:timer1;
new 
Grass[5];
new 
br=0;
new 
scfmString[250];
#define SCM SendClientMessage
#define SCFM(%1,%2,%3) format(scfmString,sizeof(scfmString),%3), SCM(%1,%2,scfmString)
public OnFilterScriptInit()
{
    
CA_Init();
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
CMD:as(playeridparams[], help
{
    for(new 
i=0i<5i++)
    {
        new 
Float:randx RandomFloat(109.2241-92.6121)+92.6121;   
        new 
Float:randy RandomFloat(-71.6366-(-57.7923))+57.7923;
        new 
Float:z;
        
CA_FindZ_For2DCoord(randxrandyz);
        
Grass[i] = CreatePlayerObject(playerid802randxrandyz+0.2000);
    }
    
timer1 repeat Tajmer(playerid);
    return 
1;
}
CMD:aa(playeridparams[], help
{
    
stop timer1;
    return 
1;
}
timer Tajmer[100](playerid)
{
    new 
Float:x,Float:y,Float:z;
    for(new 
i=0i<sizeof(Grass); i++)
    {
        
GetPlayerObjectPos(playeridGrass[i], xyz);
        if(
IsPlayerInRangeOfPoint(playerid1xyz))
        {
            
DestroyPlayerObject(playeridGrass[i]);
            
Grass[i] = 0;
            
br++;
        }
    }
    if(
br >= sizeof(Grass))
    {
        
SendClientMessage(playerid, -1,"No grass");
    }
    return 
1;

I have problem with this part:
PHP код:
        if(IsPlayerInRangeOfPoint(playerid1xyz))
        {
            
DestroyPlayerObject(playeridGrass[i]);
            
Grass[i] = 0;
            
br++;
        } 
Sometimes do this if object is already destroyed
Reply
#8

pawn Код:
if(Grass[i] != 0 && IsPlayerInRangeOfPoint(...))
or

pawn Код:
if(GetPlayerObjectPos(playerid, Grass[i], x, y, z) && IsPlayerInRangeOfPoint(...))
propably first code is better and if you want something for player it should be

Grass[playerid][i]

because if few players use /as there will be fun
Reply
#9

Thank you Jeff, I fixed it.

Quote:
Originally Posted by ******
Посмотреть сообщение
For this to be true:

br >= sizeof(Grass)

They would have to be right next to every piece of grass at the same time. Is that the case?
It gives me exactly what I want. It checks if all objects are destroyed.
Reply
#10

No they are not.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)