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

Enum Structs Available This Holiday Season


Post New Thread Reply   
 
Thread Tools Display Modes
milutinke
AlliedModders Donor
Join Date: Jun 2012
Location: Serbia
Old 11-29-2019 , 05:00   Re: Enum Structs Available This Holiday Season
Reply With Quote #31

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.
milutinke is offline
Send a message via Skype™ to milutinke
_pHabb
Senior Member
Join Date: Jul 2013
Location: GetCountry(pHabb);
Old 12-11-2019 , 14:09   Re: Enum Structs Available This Holiday Season
Reply With Quote #32

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

new players[MAXPLAYERS + 1];

// Usage: players[client] = Admin;
How this code will look in the new syntax?

Last edited by _pHabb; 12-11-2019 at 14:30.
_pHabb is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 12-11-2019 , 15:19   Re: Enum Structs Available This Holiday Season
Reply With Quote #33

Quote:
Originally Posted by _pHabb View Post
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; 
__________________
Ilusion9 is offline
LeeStrong
AlliedModders Donor
Join Date: Nov 2015
Old 12-22-2019 , 06:35   Re: Enum Structs Available This Holiday Season
Reply With Quote #34

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.

Last edited by LeeStrong; 12-22-2019 at 06:36.
LeeStrong is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 12-26-2019 , 07:52   Re: Enum Structs Available This Holiday Season
Reply With Quote #35

Quote:
Originally Posted by LeeStrong View Post
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
__________________

Last edited by MAGNAT2645; 12-26-2019 at 07:53. Reason: Added [CODE]
MAGNAT2645 is offline
LeeStrong
AlliedModders Donor
Join Date: Nov 2015
Old 12-27-2019 , 21:51   Re: Enum Structs Available This Holiday Season
Reply With Quote #36

Quote:
Originally Posted by MAGNAT2645 View Post
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.
LeeStrong is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 12-28-2019 , 00:21   Re: Enum Structs Available This Holiday Season
Reply With Quote #37

Quote:
Originally Posted by _pHabb View Post
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.

Last edited by 404UserNotFound; 12-28-2019 at 00:22.
404UserNotFound is offline
Deather
New Member
Join Date: Nov 2016
Old 06-24-2020 , 13:30   Re: Enum Structs Available This Holiday Season
Reply With Quote #38

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;
}
Deather is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-24-2020 , 14:46   Re: Enum Structs Available This Holiday Season
Reply With Quote #39

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);

__________________

Last edited by asherkin; 06-24-2020 at 14:47.
asherkin is offline
Deather
New Member
Join Date: Nov 2016
Old 06-24-2020 , 16:10   Re: Enum Structs Available This Holiday Season
Reply With Quote #40

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;
Deather 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 22:25.


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