AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Enum Structs Available This Holiday Season (https://forums.alliedmods.net/showthread.php?t=312822)

milutinke 11-29-2019 05:00

Re: Enum Structs Available This Holiday Season
 
Can we get the following methods and properties:?
  • .getEnumStructName() - Returns the name of the enum struct as a string.
  • .getMethods() - Returns array list of methods present in the enum struct.
  • [<method name>] (Example: rectangle["x"]) - Same as rectangle.x, if non existant, returns Invalid_Handle or if non existant while setting, gets created and gets assigned a value.

Those would be useful for serialization/deserialization.

_pHabb 12-11-2019 14:09

Re: Enum Structs Available This Holiday Season
 
Code:

enum _:Roles
{
    Vip,
    Moderator,
    Admin
};

new players[MAXPLAYERS + 1];

// Usage: players[client] = Admin;

How this code will look in the new syntax?

Ilusion9 12-11-2019 15:19

Re: Enum Structs Available This Holiday Season
 
Quote:

Originally Posted by _pHabb (Post 2676624)
Code:

enum _:Roles
{
    Vip,
    Moderator,
    Admin
};

new players[MAXPLAYERS + 1];

// Usage: players[client] = Admin;

How this code will look in the new syntax?

PHP Code:


enum Role
{
    
Vip 0,
    
Moderator,
    
Admin
};

Role players[MAXPLAYERS 1];
// Usage: players[client] = Admin; 


LeeStrong 12-22-2019 06:35

Re: Enum Structs Available This Holiday Season
 
Is anyone able to help with the above, like many others I'm running a fork of ckSurf which if using the latest SM compiler, will not compile due to the use of enums.

I'm not the most knowledgeable when it comes to the transitional syntax and I've been having trouble getting things to compile and function when making my own efforts to convert my fork of the timer.
Notepad++ isn't the most forthcoming either!

Sample of Code
Code:

enum MapZone
{
        zoneId,                                  // ID within the map
        zoneType,                                  // Types: Start(1), End(2), Stage(3), Checkpoint(4), Speed(5), TeleToStart(6), Validator(7), Checker(8), Stop(0)
        zoneTypeId,                        // ID of the same type eg. Start-1, Start-2, Start-3...
        Float:PointA[3],
        Float:PointB[3],
        Float:CenterPoint[3],
        String:zoneName[128],
        zoneGroup,
        Vis,
        Team,
        Float:TeleportPosition[3],
        Float:TeleportAngles[3]
}

Usage:
Code:

int g_mapZones[MAXZONES][MapZone];                                                                // Map Zone array
                        if (g_mapZones[i][zoneType] == 3 && g_mapZones[i][zoneGroup] == zonegroup)
                        {
                                StageIds[amount] = i;
                                amount++;
                        }

The above is just some example usage, but there's a lot of work to be done with this timer to make it happy with the up to date syntax. Are there any relatively simple ways to convert the above without having to make too many modifications to how they are used within the code?

Many thanks in advance for anyones input on the above.

MAGNAT2645 12-26-2019 07:52

Re: Enum Structs Available This Holiday Season
 
Quote:

Originally Posted by LeeStrong (Post 2677695)
Is anyone able to help with the above, like many others I'm running a fork of ckSurf which if using the latest SM compiler, will not compile due to the use of enums.

I'm not the most knowledgeable when it comes to the transitional syntax and I've been having trouble getting things to compile and function when making my own efforts to convert my fork of the timer.
Notepad++ isn't the most forthcoming either!

Sample of Code
Code:

enum MapZone
{
        zoneId,                                  // ID within the map
        zoneType,                                  // Types: Start(1), End(2), Stage(3), Checkpoint(4), Speed(5), TeleToStart(6), Validator(7), Checker(8), Stop(0)
        zoneTypeId,                        // ID of the same type eg. Start-1, Start-2, Start-3...
        Float:PointA[3],
        Float:PointB[3],
        Float:CenterPoint[3],
        String:zoneName[128],
        zoneGroup,
        Vis,
        Team,
        Float:TeleportPosition[3],
        Float:TeleportAngles[3]
}

Usage:
Code:

int g_mapZones[MAXZONES][MapZone];                                                                // Map Zone array
                        if (g_mapZones[i][zoneType] == 3 && g_mapZones[i][zoneGroup] == zonegroup)
                        {
                                StageIds[amount] = i;
                                amount++;
                        }

The above is just some example usage, but there's a lot of work to be done with this timer to make it happy with the up to date syntax. Are there any relatively simple ways to convert the above without having to make too many modifications to how they are used within the code?

Many thanks in advance for anyones input on the above.

Code:

enum struct MapZone
{
        int zoneId,                                  // ID within the map
        int zoneType,                                  // Types: Start(1), End(2), Stage(3), Checkpoint(4), Speed(5), TeleToStart(6), Validator(7), Checker(8), Stop(0)
        int zoneTypeId,                        // ID of the same type eg. Start-1, Start-2, Start-3...
        float PointA[3],
        float PointB[3],
        float CenterPoint[3],
        char zoneName[128],
        int zoneGroup,
        int Vis,
        int Team,
        float TeleportPosition[3],
        float TeleportAngles[3]
}

MapZone g_mapZones[MAXZONES];

Example, instead of g_mapZones[i][zoneType] use g_mapZones[i].zoneType

LeeStrong 12-27-2019 21:51

Re: Enum Structs Available This Holiday Season
 
Quote:

Originally Posted by MAGNAT2645 (Post 2678080)
Code:

enum struct MapZone
{
        int zoneId,                                  // ID within the map
        int zoneType,                                  // Types: Start(1), End(2), Stage(3), Checkpoint(4), Speed(5), TeleToStart(6), Validator(7), Checker(8), Stop(0)
        int zoneTypeId,                        // ID of the same type eg. Start-1, Start-2, Start-3...
        float PointA[3],
        float PointB[3],
        float CenterPoint[3],
        char zoneName[128],
        int zoneGroup,
        int Vis,
        int Team,
        float TeleportPosition[3],
        float TeleportAngles[3]
}

MapZone g_mapZones[MAXZONES];

Example, instead of g_mapZones[i][zoneType] use g_mapZones[i].zoneType

Brilliant! This looks easier than I anticipated, I'll give this a try tomorrow and report in.
Thank you so much. :)

404UserNotFound 12-28-2019 00:21

Re: Enum Structs Available This Holiday Season
 
Quote:

Originally Posted by _pHabb (Post 2676624)
Code:

enum _:Roles

I wish I knew why the hell the enum is using _: which is the old syntax version of view_as<int>.

enum view_as<int>(Roles) just doesn't seem right to me.

Deather 06-24-2020 13:30

Re: Enum Structs Available This Holiday Season
 
Is it possible to return enum struct in function? Code below doesn't work.

Code:

enum struct STest
{
    int a;
    int b;
}
STest test;

STest GetTest()
{
  return test;
}


asherkin 06-24-2020 14:46

Re: Enum Structs Available This Holiday Season
 
The compiler doesn't appear to currently understand it as a type when parsing the function declaration, interestingly using it as any[] appears to work correctly but I have no idea if that is intended.

As with other array-like things in SourcePawn, it's almost certainly better to pass it as a param to be filled in by the callee.

PHP Code:

enum struct STest
{
    
int a;
    
int b;
}

STest test;

any[] GetTest()
{
   return 
test;
}

public 
void OnPluginStart()
{
    
test.4;
    
test.8;
    
    
STest other;
    
other GetTest();
    
    
PrintToServer("%d = %d, %d = %d"test.aother.atest.bother.b);



Deather 06-24-2020 16:10

Re: Enum Structs Available This Holiday Season
 
Code:

enum struct STest
{
    int a;
    int b;
}
STest test;

STest[] GetTest()
{
  return test;
}

Its works, but there is a problem with calling struct methods.

There is also a problem with using the same struct type as a method argument type:
Code:

enum
struct STest
{
    int a;

    void Add(STest x)
    {
      a += x.a;
    }
}
STest test;



All times are GMT -4. The time now is 13:21.

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