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

New API and Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Cookies.net
Senior Member
Join Date: Jan 2011
Old 07-31-2014 , 07:42   Re: New API and Syntax
Reply With Quote #81

Quote:
Originally Posted by WildCard65 View Post
Is there going to be inheritence? Cause it'll be a cool thing to have:
ex:
main method map for clients is located in clients.inc and contains all natives related to clients that are in clients.inc
Another method map inherits the clients.inc main method map, adding it's natives to it's own methodmap while still able to use clients.incs methodmap functions.
etc...
https://wiki.alliedmods.net/SourcePa...ax#Inheritance
Cookies.net is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 08-01-2014 , 18:36   Re: New API and Syntax
Reply With Quote #82

With the new type of variable declaration can you make them static? or static only support old pawn style (where it a declaration type itself).

E.g: myfunction() { static int myAge; PrintToServer("%d", myAge++); }

EDIT: nvm, tested and it work great. Good job. I love it.

Last edited by Mathias.; 08-01-2014 at 18:44.
Mathias. is offline
kossolax
AlliedModders Donor
Join Date: Jan 2008
Location: Belgium
Old 08-05-2014 , 05:02   Re: New API and Syntax
Reply With Quote #83

Quote:
Originally Posted by BAILOPAN View Post
kossolax: no, but you can do this:

PHP Code:
methodmap Player
{
    public 
Kick() = KickPlayer
}

void KickPlayer(Player player, const char[] msg, ...)
{
   ...

The public X() = Y syntax is basically saying "bind player.X to call Y instead".

Hello,

What about function pointers? Current synthax is horrible.

PHP Code:
public sub(client) return 42;
functag something public(client);
public 
doh(clientsomething:getVal ) {
   new 
tmp;
   
Call_StartFunction(INVALID_HANDLEgetVal);
   
Call_PushCell(client);
   
Call_Finish(tmp);
}
doh(clientsub); 
To something more friendly, like...
PHP Code:
public sub(client) return 42;
public 
doh(client, Function:fct(client)) {
    new 
tmp fct(client);
}
doh(clientsub); 
It will be same as your exemple?

Last edited by kossolax; 08-05-2014 at 05:21.
kossolax is offline
BAILOPAN
Join Date: Jan 2004
Old 08-05-2014 , 13:18   Re: New API and Syntax
Reply With Quote #84

No, sorry, function pointers are not part of the transitional syntax. I know it's hard to distinguish between what's low-hanging-fruit and not, but function pointers cannot be implemented safely in the current compiler. I'd love to find a way to do them, but it won't be soon.
__________________
egg

Last edited by BAILOPAN; 08-05-2014 at 14:27.
BAILOPAN is offline
kossolax
AlliedModders Donor
Join Date: Jan 2008
Location: Belgium
Old 08-06-2014 , 05:06   Re: New API and Syntax
Reply With Quote #85

Alright, thank's for your answer :-)
kossolax is offline
SkydiveX
Member
Join Date: Jul 2012
Location: England
Old 08-18-2014 , 10:16   Re: New API and Syntax
Reply With Quote #86

Oh boy! This sure is exciting!
__________________

_____________________________________________ _______________
Pastafarian and proud!
SkydiveX is offline
BAILOPAN
Join Date: Jan 2004
Old 08-18-2014 , 15:17   Re: New API and Syntax
Reply With Quote #87

Update: I think function pointers are possible in the current design, though true closures are not (meaning we can't do nested functions).
__________________
egg
BAILOPAN is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 08-21-2014 , 20:18   Re: New API and Syntax
Reply With Quote #88

I've just tried ur following example:

PHP Code:
enum Player:
{
    
SERVER_PLAYER 0,
}

methodmap Player
{
    public 
void Kick(const char[] message) {
        
KickClent(this.Index"%s"message);
    }
    
property int Health {
        public 
get() {
            return 
GetClientHealth(this.Index);
        }
    }
    
property int Index {
        public 
get() {
            return 
int(this);
        }
    }

and it do not compile (yes 1.7)

I got some errors such as invalid expression, assumed zero at the return int(this) line. I had to swap the propriety above the functions because it could not find the method, also there were an error on the command "KickClient" (wrote "KickClent")

I'm trying to understand the concept you give us in the first page but I cannot make it work as intended.

Here the full code

PHP Code:
#include <sourcemod>


enum Player:
{
    
SERVER_PLAYER 0,
}

methodmap Player
{
    
property int Index {
        public 
get() {
            return 
int(this);
        }
    }

    public 
void Kick(const char[] message) {
        
KickClient(this.Index"%s"message);
    }
    
property int Health {
        public 
get() {
            return 
GetClientHealth(this.Index);
        }
    }
}

public 
OnPluginStart()
{
    for (
int i 1MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
KickClient(i"test");
            
/*Player player = i;
            PrintToServer("player %N (index %d) have %d health!", i, player.Index, player.Health);*/
        
}
    }

EDIT #1:

I've tried to remove int() wrap around this and it does a tag mismatch error, but if I decide to return 0 it compile correctly.
The int() cast dosnt work?

EDIT #2:
There is a problem with the cast, same error with return int(2.1);

Temporary ugly hax0r fix: return _:this;

EDIT #3:
How do you make the 'object' have the correct player index. Player player = i; didnt work (didnt really expect it to work) but I'm still curious where you were going with this example.

Last edited by Mathias.; 08-21-2014 at 20:37.
Mathias. is offline
BAILOPAN
Join Date: Jan 2004
Old 08-22-2014 , 14:29   Re: New API and Syntax
Reply With Quote #89

@Black-Rabbit: there is no cast yet. You have to use re-tagging which is slightly different from a cast. I.e., _:this. I'll work on cast support soon.
__________________
egg
BAILOPAN is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 08-22-2014 , 14:48   Re: New API and Syntax
Reply With Quote #90

@BAILOPAN: What about the index, I'm not quiet sure what the purpose of methodmap yet, is it possible to assign a index to my methodmap so I can actually do actions to the players? I know that were not there purpose and you will work on classes soon enough but I'm curious if there is a way to implement the concept you try to demonstrate.
Mathias. 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 21:13.


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