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

Enum Structs Available This Holiday Season


Post New Thread Reply   
 
Thread Tools Display Modes
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-25-2018 , 06:30   Re: Enum Structs Available This Holiday Season
Reply With Quote #11

__________________
Do not Private Message @me
Bacardi is offline
LeToucan
New Member
Join Date: Jan 2016
Old 12-26-2018 , 15:33   Re: Enum Structs Available This Holiday Season
Reply With Quote #12

Quote:
Originally Posted by Bacardi View Post
So since enum structs are treated as an array, when using array fields they are treated as 2 dimensional arrays, and thus wouldn't correctly work with ArrayLists? The section outlining using them with ArrayLists could be updated, as this part makes it seem like my snippet should work.
Quote:
The exception is when interacting with opaque data structures like ArrayList. For example, this is considered valid:
LeToucan is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-26-2018 , 16:10   Re: Enum Structs Available This Holiday Season
Reply With Quote #13

You never gave blocksize to the ArrayList constructor.
__________________
klippy is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-26-2018 , 16:20   Re: Enum Structs Available This Holiday Season
Reply With Quote #14

Quote:
Originally Posted by LeToucan View Post
So since enum structs are treated as an array, when using array fields they are treated as 2 dimensional arrays, and thus wouldn't correctly work with ArrayLists? The section outlining using them with ArrayLists could be updated, as this part makes it seem like my snippet should work.
While I can't say I know how Pawn internally treats 2-dimensional arrays, in this case you're storing an array reference nside another array.

It helps if you know arrays are a reference type. When I say that, I mean when you do this:

PHP Code:
int players[MAXPLAYERS+1]; 
you're actually creating an array with a length of MAXPLAYERS+1, then storing the memory address of the start of that array in players
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-26-2018 at 16:20. Reason: +words
Powerlord is offline
LeToucan
New Member
Join Date: Jan 2016
Old 12-26-2018 , 16:23   Re: Enum Structs Available This Holiday Season
Reply With Quote #15

Quote:
Originally Posted by KliPPy View Post
You never gave blocksize to the ArrayList constructor.
Thank you, after setting the blocksize to sizeof(f), it worked perfectly.
LeToucan is offline
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 01-05-2019 , 21:52   Re: Enum Structs Available This Holiday Season
Reply With Quote #16

BAILOPAN, great update, so handy, btw can we wait some update in methodmaps part ? We need some improvements there, something look like a clases with proper constructor and destructor or may be a posibility to create values inside a methodmap class, like in a new struct and use them only there
__________________
gubka is offline
Send a message via ICQ to gubka
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 01-06-2019 , 09:02   Re: Enum Structs Available This Holiday Season
Reply With Quote #17

methodmaps != classes

While 'enum structs' can hold multiple values because they are arrays, methodmaps can only hold one.

If you want to store something *in* methodmaps use StringMap's (or any other list). StringMap's are more readable. Example:

PHP Code:
methodmap Player StringMap
{
    public 
Player(int id)
    {
        
StringMap map = new StringMap();
        
        
map.SetValue("id"id);
        
map.SetValue("userid"GetClientUserId(id));
        
map.SetValue("money"100);
        
        return 
view_as<Player>(map);
    }
    
    
property int Userid
    
{
        public 
get() {
            
int i;
            
this.GetValue("userid"i);
            return 
i;
        }
    }
    
    
property int Id
    
{
        public 
get() {
            
int i;
            
this.GetValue("id"i);
            return 
i;
        }
    }
    
    
property int Money
    
{
        public 
get() {
            
int i;
            
this.GetValue("money"i);
            return 
i;
        }
        public 
set(int i) {
            
this.SetValue("money"i);
        }
    }
    
    public 
bool IsValid()
    {
        return (
GetClientOfUserId(this.Userid) > 0);
    }
    
    public 
bool InGame()
    {
        return (
IsClientInGame(this.Id));
    }
}

public 
void OnClientPutInServer(int client)
{
    
Player player = new Player(client);
    
    
CreateTimer(30.0SetPlayerMoneyTimerplayer);
}

public 
Action SetPlayerMoneyTimer(Handle timerPlayer player)
{
    if(!
player.IsValid() || !player.InGame())
        return;
    
    
player.Money 2500;
    
    
delete player;

if you remove the sugar it will look like this (decompiled):
PHP Code:
Player:Player.Player(id)
{
    new 
StringMap:map StringMap.StringMap();
    
StringMap.SetValue(map"id"idtrue);
    
StringMap.SetValue(map"userid"GetClientUserId(id), true);
    
StringMap.SetValue(map"money"any:100true);
    return 
map;
}

Player.Userid.get(Player:this)
{
    new 
i;
    
StringMap.GetValue(this"userid"i);
    return 
i;
}

Player.Id.get(Player:this)
{
    new 
i;
    
StringMap.GetValue(this"id"i);
    return 
i;
}

void:Player.Money.set(Player:thisi)
{
    
StringMap.SetValue(this"money"itrue);
    return 
void:0;
}

bool:Player.IsValid(Player:this)
{
    return 
GetClientOfUserId(Player.Userid.get(this)) > 0;
}

bool:Player.InGame(Player:this)
{
    return 
IsClientInGame(Player.Id.get(this));
}

public 
void:OnClientPutInServer(client)
{
    new 
Player:player Player.Player(client);
    
CreateTimer(30.0SetPlayerMoneyTimerplayer0);
    return 
void:0;
}

public 
Action:SetPlayerMoneyTimer(Handle:timerPlayer:player)
{
    new 
var1;
    if (!
Player.IsValid(player) || !Player.InGame(player))
    {
        return 
Action:0;
    }
    
Player.Money.set(player2500);
    
CloseHandle(player);
    
player MissingTAG:0;
    return 
Action:0;

__________________

Last edited by Timocop; 01-06-2019 at 09:07.
Timocop is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-06-2019 , 09:38   Re: Enum Structs Available This Holiday Season
Reply With Quote #18

New-style enum structs having a "methodmap" built-in is meant to solve the problem of methodmaps not having storage - what is lacking?
__________________
asherkin is offline
Santi.
Member
Join Date: Oct 2010
Location: Cordoba(Argentina)
Old 01-09-2019 , 16:21   Re: Enum Structs Available This Holiday Season
Reply With Quote #19

Quote:
Originally Posted by BAILOPAN View Post
Hi Folks,

As of PR #934, SourceMod 1.10 has support for enum structs. This is some long-overdue syntactic sugar that makes SourcePawn feel more like a real language. Enum Structs are internally implemented as arrays, but the syntax is a lot nicer than before and we've fixed a lot of the corner cases and rough edges around using them. You can also have enum struct methods now.

You can read more about enum structs either in the Transitional Syntax Docs, or in the commit message.

If you're too impatient to read that, I'll just copy and paste the sample code from the doc:

PHP Code:
enum struct Rectangle {
  
int x;
  
int y;
  
int width;
  
int height;
 
  
int Area() {
    return 
this.width this.height;
  }
};
 
void DoStuff(const Rectangle r) {
  
PrintToServer("%d, %d, %d, %d"r.xr.yr.widthr.height);

I love you man.. this is what we needed. Thanks bro!
Santi. is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-07-2019 , 00:48   Re: Enum Structs Available This Holiday Season
Reply With Quote #20

I can't help but notice when I try to include an enum struct in a native definition that the compiler tells me that I can't do this:

Code:
error 135: cannot use enum struct type "MapChoices_GetMapData" in natives
Won't this limit their usefulness?

Also, the error is reporting the native name rather than the enum struct name.
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 19:45.


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