AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   convert enum to number and back. right method (https://forums.alliedmods.net/showthread.php?t=335559)

karaulov 12-14-2021 03:02

convert enum to number and back. right method
 
How to convert TeamName to integer and back ?

new integer1 = TEAM_CT;

new TeamName:team1 = 2;

tag mismatch

Natsheh 12-14-2021 03:50

Re: convert enum to number and back. right method
 
Where is your enum?

And what do you mean with that title? O_o?

Supremache 12-14-2021 04:24

Re: convert enum to number and back. right method
 
Huh ?

Simple method to replace team name:
PHP Code:

new const szTeamName[ ][ ] = { "Unassigned",  "Terrorist""Counter-Terrorist""Spectator" }

public 
Ham_Spawnid )
{
    new 
iTeam get_user_teamid );
    
client_printidprint_chat"You team is: %s"szTeamNameiTeam ] )



karaulov 12-14-2021 05:13

Re: convert enum to number and back. right method
 
No need just cast between enums and integers.

new integer1 = TEAM_CT;
new TeamName:team1 = 2;
tag mismatch

How to convert enum to integer and back without tag mismatch))))

OciXCrom 12-14-2021 05:20

Re: convert enum to number and back. right method
 
Code:
new integer1 = _:TEAM_CT new TeamName:team1 = TeamName:2

The variable tag must be the same as the value tag.

_: is used as a blank tag.

jimaway 12-14-2021 05:37

Re: convert enum to number and back. right method
 
new integer1 = _:TEAM_CT;

new TeamName:team1 = TeamName:2;

HamletEagle 12-14-2021 10:14

Re: convert enum to number and back. right method
 
Quote:

Originally Posted by OciXCrom (Post 2765961)
new integer1 = _:TEAM_CT
new TeamName:team1 = TeamName:2

The variable tag must be the same as the value tag.

_: is used as a blank tag.

I think it is more intuitive to explain _: as detagging(removing the tag) than it being a blank tag.

Also, tagging/detagging is only needes for strong tags(starting with a upper case letter). For weak tags nothing needs to be done.


All times are GMT -4. The time now is 11:39.

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