AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How does pawn handle arrays and which way is better. (https://forums.alliedmods.net/showthread.php?t=214880)

.Dare Devil. 04-30-2013 18:55

How does pawn handle arrays and which way is better.
 
Hello, Im pretty curious about arrays like this
PHP Code:

new something[256

now there is
PHP Code:

new something[4// lets do small array for example, i ofcourse prefer always the big ones :)

public myfunction(posvalue)
{
     
something[pos] = value



is it same like this?
PHP Code:

new something0,something1,something2,something3
public myfunction(posvalue)
{
     switch(
pos)
    {
        case 
0something0 value
        
case 1something1 value
        
case 2something2 value
        
case 3something3 value

    
}



the way i understand things right now is that the first code is better and faster way and it does not matter if the array size is big or small, it does not effect the cpu speed.

I was an idea for creating big array like this Float:chuckdata[8000][3]
so inside of chuckdata are costom areas ( values are in bit )
so i can just easily check that if player is in costom area
PHP Code:

static Float:o[3],ab
pev
(idpev_origino)
for( 
03a++ )  
{
floatround(o[a] + 4000.0)
// i dont know that if its right, i dont know about bits, never tested them and i was thinking that they are useless what is very wrong. I want to check here like if( o[a] != mybit) you know what i mean with that... :)
if( chuckdata[b][a] ~ mybit) return
}

// and now if cpu is here then player is standing in area what is in my database.
// i need to use bits because then i can but more than one areas in one place for example ( and also if area is inside of ohter area, bits will help me. ) 

2years ago i didn't care about coding methods for example it was fine to me to check what weapon player is holding in prethink. If that was working then it was just fine to me but now i want that everything is perfect.

I hope i can get some feedback ( my "string checking in prethink" topic is like an empty desert : /)
Thanks!

fysiks 04-30-2013 23:51

Re: How does pawn handle arrays and which way is better.
 
Quote:

Originally Posted by .Dare Devil. (Post 1943302)
Hello, Im pretty curious about arrays like this
PHP Code:

new something[256

now there is
PHP Code:

new something[4// lets do small array for example, i ofcourse prefer always the big ones :)

public myfunction(posvalue)
{
     
something[pos] = value



is it same like this?
PHP Code:

new something0,something1,something2,something3
public myfunction(posvalue)
{
     switch(
pos)
    {
        case 
0something0 value
        
case 1something1 value
        
case 2something2 value
        
case 3something3 value

    
}



the way i understand things right now is that the first code is better and faster way and it does not matter if the array size is big or small, it does not effect the cpu speed.

You can test it to see if it works the same. In your example the difference is likely negligible and you should code for readability/flexibility/maintainability.


Quote:

Originally Posted by .Dare Devil. (Post 1943302)
I was an idea for creating big array like this Float:chuckdata[8000][3]
so inside of chuckdata are costom areas ( values are in bit )
so i can just easily check that if player is in costom area
PHP Code:

static Float:o[3],ab
pev
(idpev_origino)
for( 
03a++ )  
{
floatround(o[a] + 4000.0)
// i dont know that if its right, i dont know about bits, never tested them and i was thinking that they are useless what is very wrong. I want to check here like if( o[a] != mybit) you know what i mean with that... :)
if( chuckdata[b][a] ~ mybit) return
}

// and now if cpu is here then player is standing in area what is in my database.
// i need to use bits because then i can but more than one areas in one place for example ( and also if area is inside of ohter area, bits will help me. ) 


What in the world are you trying to do here? If you think you need to make an array that big then I would guess that you need to rethink how you are doing it.

ConnorMcLeod 05-01-2013 06:04

Re: How does pawn handle arrays and which way is better.
 
Quote:

Originally Posted by fysiks (Post 1943436)
What in the world are you trying to do here? If you think you need to make an array that big then I would guess that you need to rethink how you are doing it.

I would event say more :
What in the world are you trying to do here? If you think you need to make an array that big then I would guess that you need to rethink how you are doing it.

.Dare Devil. 05-01-2013 14:58

Re: How does pawn handle arrays and which way is better.
 
If someone will say that in third time, that will be funny.
Thanks guys, you really helped me.

Backstabnoob 05-01-2013 15:27

Re: How does pawn handle arrays and which way is better.
 
It's the truth, your code makes no sense, if you want to make a 4000+ size array then you really do need to rethink what you're doing.


All times are GMT -4. The time now is 10:57.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.