Raised This Month: $59 Target: $400
 14% 

New API and Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
IceCucumber
Member
Join Date: Dec 2011
Old 04-05-2016 , 22:45   Re: New API and Syntax
Reply With Quote #721

Quote:
Originally Posted by WildCard65 View Post
it's:
PHP Code:
 const char foo[] = "bar"
I'm getting a
Quote:
error 001: expected token: "=", but found "["
I'm declaring this in global scope if that makes any difference.
IceCucumber is offline
IceCucumber
Member
Join Date: Dec 2011
Old 04-06-2016 , 16:11   Re: New API and Syntax
Reply With Quote #723

Quote:
Originally Posted by Merudo View Post
Huh. Well, hopefully it gets fixed eventually
IceCucumber is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 04-17-2016 , 14:15   Re: New API and Syntax
Reply With Quote #724

question.

Since the methodmaps are just syntactic sugar, does that I mean I can use the constructor function to directly access properties and method functions instead of creating an instance of the methodmap?

Here's what I mean in code.

PHP Code:
methodmap BaseMap
{
    public 
BaseMap (const int indbool uid false)
    {
        if (
uid) {
            return 
view_as<BaseMap>( ind );
        }
        return 
view_as<BaseMap>( GetClientUserId(ind) );
    }

    
property int userid {
        public 
get()                { return view_as<int>(this); }
    }
    
property int index {
        public 
get()                { return GetClientOfUserIdthis.userid ); }
    }

    public 
void Funcz () {}
};

public 
void OnPluginStart ()
{
    
int Arr[MAXPLAYERS+1];

    for (
int i MaxClients ; --i)
    {
        
Arr[i] = BaseMap(i).userid;
        
BaseMap(i).Funcz();
    }

Secondly, would it be more efficient to do that in a loop or create an instance before hand and reassign it each loop?
__________________

Last edited by nergal; 04-17-2016 at 14:16.
nergal is offline
You9
Member
Join Date: Mar 2016
Old 04-21-2016 , 12:27   Re: New API and Syntax
Reply With Quote #725

One little question:
Code:
gShadow_NoWeapons = bool:StringToInt(newValue);
How that "bool:" should be in new syntax?
You9 is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 04-21-2016 , 13:26   Re: New API and Syntax
Reply With Quote #726

You can do
PHP Code:
gShadow_NoWeapons = !!StringToInt(newValue); 
If this is a convar hook callback (which it looks like) you can also use the BoolValue property of the convar handle
PHP Code:
gShadow_NoWeapons cvar.BoolValue
__________________

Last edited by Impact123; 04-21-2016 at 13:34.
Impact123 is offline
BAILOPAN
Join Date: Jan 2004
Old 04-22-2016 , 18:02   Re: New API and Syntax
Reply With Quote #727

Quote:
Originally Posted by nergal View Post
question.

Since the methodmaps are just syntactic sugar, does that I mean I can use the constructor function to directly access properties and method functions instead of creating an instance of the methodmap?

Here's what I mean in code.

PHP Code:
methodmap BaseMap
{
    public 
BaseMap (const int indbool uid false)
    {
        if (
uid) {
            return 
view_as<BaseMap>( ind );
        }
        return 
view_as<BaseMap>( GetClientUserId(ind) );
    }

    
property int userid {
        public 
get()                { return view_as<int>(this); }
    }
    
property int index {
        public 
get()                { return GetClientOfUserIdthis.userid ); }
    }

    public 
void Funcz () {}
};

public 
void OnPluginStart ()
{
    
int Arr[MAXPLAYERS+1];

    for (
int i MaxClients ; --i)
    {
        
Arr[i] = BaseMap(i).userid;
        
BaseMap(i).Funcz();
    }

Secondly, would it be more efficient to do that in a loop or create an instance before hand and reassign it each loop?
Yes, you can do this. I don't really understand your efficiency question, but since methodmaps don't allocate memory it shouldn't matter. There are a few antipatterns in your code though. In general it is not a good idea to have one parameter mean something entirely different based on a flag. It's better to do this:

PHP Code:
methodmap BaseMap
{
    public 
BaseMap(int client) {
        return 
view_as<BaseMap>(GetClientUserId(client));
    }

    public static 
BaseMap FromUserId(int userid) {
        return 
view_as<BaseMap>(userid);
    }

    
property int userid {
        public 
get() {
          return 
view_as<int>(this);
        }
    }
    
property int index {
        public 
get() {
            return 
GetClientOfUserId(this.userid);
        }
    }
}; 
This is a common way of having two constructors for clarity:
PHP Code:
BaseMap map1 BaseMap(client);
BaseMap map2 BaseMap.FromUserId(userid); 
Constructing an object multiple times just to access properties is also an anti-pattern, but since your methodmap doesn't do anything effectful or expensive it doesn't matter.
__________________
egg

Last edited by BAILOPAN; 04-22-2016 at 18:03.
BAILOPAN is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 04-23-2016 , 14:05   Re: New API and Syntax
Reply With Quote #728

Quote:
Originally Posted by BAILOPAN View Post
Yes, you can do this. I don't really understand your efficiency question, but since methodmaps don't allocate memory it shouldn't matter. There are a few antipatterns in your code though. In general it is not a good idea to have one parameter mean something entirely different based on a flag. It's better to do this:

PHP Code:
methodmap BaseMap
{
    public 
BaseMap(int client) {
        return 
view_as<BaseMap>(GetClientUserId(client));
    }

    public static 
BaseMap FromUserId(int userid) {
        return 
view_as<BaseMap>(userid);
    }

    
property int userid {
        public 
get() {
          return 
view_as<int>(this);
        }
    }
    
property int index {
        public 
get() {
            return 
GetClientOfUserId(this.userid);
        }
    }
}; 
This is a common way of having two constructors for clarity:
PHP Code:
BaseMap map1 BaseMap(client);
BaseMap map2 BaseMap.FromUserId(userid); 
Constructing an object multiple times just to access properties is also an anti-pattern, but since your methodmap doesn't do anything effectful or expensive it doesn't matter.
I see, thanks Bailopan! Before I stop lurking for a long time, I have one last question.

Are timers still limited to 0.1 seconds for the smallest possible interval or has this been changed?

If they still are limited to 0.1s, will that change in the future?
__________________

Last edited by nergal; 04-23-2016 at 14:05.
nergal is offline
BAILOPAN
Join Date: Jan 2004
Old 04-23-2016 , 18:11   Re: New API and Syntax
Reply With Quote #729

They are still limited to 0.1s (100ms) for practicality. A bunch of games process new frames every ~30ms, which means our timers could be pretty inaccurate if we went below that. For example if you had a 20ms timer, it might work on a game that ticks every 10ms - but on a 30ms game it could wait 50ms before firing again.

Instead, we guarantee that a timer will fire within 100ms of accuracy. If you specify something more precise, like ".10289381" (which is allowed, since it's a float), that 2.89381ms won't do you any good.

Basically if you need finer grained control, you should (carefully) use OnGameFrame.

A good thing to read when thinking about timers, btw, is here: https://blogs.msdn.microsoft.com/old...02-00/?p=34333
__________________
egg

Last edited by BAILOPAN; 04-23-2016 at 18:15.
BAILOPAN is offline
kossolax
AlliedModders Donor
Join Date: Jan 2008
Location: Belgium
Old 05-03-2016 , 07:14   Re: New API and Syntax
Reply With Quote #730

I could not pass DataPack using native. I've tried to pass Handle instead, but the issue was similar.

With DataPack
PHP Code:
DataPack dp view_as<DataPack>(GetNativeCell(1));
dp.Position 0;
Native "SetPackPosition" reportedInvalid data pack handle 60f7069e (error 5
With Handle
PHP Code:
Handle dp view_as<Handle>(GetNativeCell(1));
ResetPack(dp);
Native "ResetPack" reportedInvalid data pack handle 108d00c8 (error 5

Is it a normal behavior?
kossolax is offline
Reply


Thread Tools
Display Modes

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 11:33.


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