I play a game which I have ac# written source to, and I'm trying to make a command. Say I have these constants:
public class Flags {
public const ulong
Normal = 0x0,
FlashingName = 0x1,
Dizzy = 1UL << 58,
DivineShield = 1UL << 57,
Poisoned = 0x2
}
And I want to try a command like this:
case "addflag":{
client.Entity.AddTopStatus(Update.Flags.(Data[1]), DateTime.Now.AddDays(1), false);
break;
}
Where in game I would type @addflag Dizzy (dizzy in place of (data[1]) in the constants), kind of like if the command was:
client.Entity.AddTopStatus(Update.Flags.Dizzy, DateTime.Now.AddDays(1), false);
but since the (data[1]) is there, I can do it by command, rather than calling it directly. I can choose any constant, rather than calling out each one seperately.
This code I get an error in, but that was expected. Is there someway I can do this? (i hope you guys are understanding me, im not very good with c# so sorry if this is confusing)
Make Flags
an enum
and then use Enum.Parse to convert data[1]
to the appropriate flag.
public enum Flags : ulong
{
Normal = 0x0,
FlashingName = 0x1,
Dizzy = 1UL << 58,
DivineShield = 1UL << 57,
Poisoned = 0x2
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.