Raised This Month: $51 Target: $400
 12% 

arrayset and float


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 05-28-2014 , 15:34   arrayset and float
Reply With Quote #1

Why does this give 2 tag mismatches for the float one? Or am I thinking wrong??

PHP Code:
#include <amxmodx>

new iVar[33], bool:bVar[33], Float:flVar[33]

public 
plugin_init()
{
    
arrayset(iVar032)
    
arrayset(bVarfalse32)
    
arrayset(flVar0.032)

__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-28-2014 , 15:50   Re: arrayset and float
Reply With Quote #2

Look at the definition of the function. Are the args declared as floats?
__________________
fysiks is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-28-2014 , 15:54   Re: arrayset and float
Reply With Quote #3

You cannot use arrayset for floats, just do

PHP Code:
arrayset_fFloat: Array[ ], Floatvaluesize )
{
     for( new 
isize++ )
     {
          Array[ 
] = value
     
}

__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 05-28-2014 , 16:01   Re: arrayset and float
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
Are the args declared as floats?
You're right.

Thanks for the function backstab.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Old 05-28-2014, 16:09
YamiKaitou
This message has been deleted by YamiKaitou. Reason: wow, I'm late
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-28-2014 , 18:42   Re: arrayset and float
Reply With Quote #5

PHP Code:
arrayset(_:flVar_:0.0sizeof(flVar)); 
__________________
hleV is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-28-2014 , 19:58   Re: arrayset and float
Reply With Quote #6

Or he just uses the function I posted which looks way more clean.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-29-2014 , 11:27   Re: arrayset and float
Reply With Quote #7

Why would he declare an additional function in his plugin when there's a built-in AMXX native for that? For large arrays it will be way more efficient.

All I did was negate your statement that you cannot use the native for floats.
__________________

Last edited by hleV; 05-29-2014 at 11:35.
hleV is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-29-2014 , 13:28   Re: arrayset and float
Reply With Quote #8

Quote:
Originally Posted by hleV View Post
For large arrays it will be way more efficient.
No, not really.

PHP Code:
static cell AMX_NATIVE_CALL arrayset(AMX *amxcell *params)
{
    
cell value params[2];

    if (!
value)
    {
        
memset(get_amxaddr(amxparams[1]), 0params[3] * sizeof(cell));
    } else {
        
int size params[3];
        
cell *addr get_amxaddr(amxparams[1]);
        for (
int i=0i<sizei++)
        {
            
addr[i] = value;
        }
    }

    return 
1;

I doubt there's any noticeable difference between a for( ) loop and an old assembler function memset. Also, you're saving one native call too, so if there IS any difference, this will likely negate that.

Quote:
Originally Posted by hleV View Post
All I did was negate your statement that you cannot use the native for floats.
Sorry if I offended you in some way, but I'm just saying it makes way more sense to have an arrayset_f instead of using a built-in native at the cost of lost readability.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-29-2014 , 14:29   Re: arrayset and float
Reply With Quote #9

You're the one who seems offended, hence your first reply to me which makes no sense.

Assigning values of a large array in a module will be more efficient than in a plugin, and tagging/detagging variables is a part of Pawn language and it in no way makes it less readable (unless you're new to it?), let alone worth coming up with less efficient ways of doing the same.

If _: makes it unreadable to you, then why not just
PHP Code:
#define arrayset_f(%1,%2,%3) arrayset(_:%1, _:%2, %3) 
I answered the OP's question. It's a better answer than yours. Move on.
__________________

Last edited by hleV; 05-29-2014 at 14:32.
hleV is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-29-2014 , 15:55   Re: arrayset and float
Reply With Quote #10

I'm in no way new to Pawn and I do think that detagging floats might be confusing for a whole lot of people. I agree that your answer is better, but you just use some arguments which don't make much sense. Worrying about speed is kind of silly when you're talking about something like this.

PHP Code:
#include < amxmodx >


public plugin_init( )
{
    new 
Float:aArray512 ]
    
    
arrayset_:aArray_:0.0sizeof aArray )
    
arrayset_faArray0.0sizeof aArray )
}



arrayset_fFloataArray[ ], Floatvaluesize )
{
     for( new 
isize++ )
     {
          
aArray] = value
     
}

Code:
type |                             name |      calls | time / min / max
-------------------------------------------------------------------
   n |                         arrayset |          1 | 0.000001 / 0.000001 / 0.000001
   p |                      plugin_init |          1 | 0.000001 / 0.000001 / 0.000001
   f |                       arrayset_f |          1 | 0.000002 / 0.000002 / 0.000002
0 natives, 0 public callbacks, 1 function calls were not executed.
512 is already a lot unless you want to use the array for a string, in which case you can just set the first cell to EOS. Let's just leave the "this is more efficient" argument completely out. If you need to null a 512-cell array in pawn then you're probably doing something wrong to begin with.

@OP: Use either detagging or define, it's a better solution as hleV said, however I still stand behind my argument being that what I posted is not wrong either and it probably doesn't matter at all which you use.
__________________
Currently busy working on a very large scale anime database project.

Last edited by Backstabnoob; 05-29-2014 at 17:11.
Backstabnoob is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:56.


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