Hello, i have question, is there more "correct" way to get int value from rust enum? For example i need integer from BuildingGrade.Enum, after some attems i found that tostring returns like "Value: number" so i can keep only numbers like this:
It worked fine, and do what i want, but i thing there should be some more correct way of this... Any suggestions?Code:local grade = string.match(tostring(buildingblock.grade),"%d+")
Get enum int in lua?
Discussion in 'Rust Development' started by AlexALX_[rus-ua], Mar 11, 2015.
-
There are a few different ways on how you can approach this but the way you are doing it will do just fine.
Another approach would be looping the enum table in OnServerInitialized or something and create your own enum table that (enumtable = { "Twigs" = 0, "Wood" = 1, ...... }) and just call that when you need to grab a grade (enumtable[buildingblock.grade:ToString()]).