GDScript에서 enum을 이렇게 선언했어요:
enum Motion = { IDLE, STEPPING, DASHING }
가능한 모든 변형을 나열하지 않고 enum 변형을 무작위로 고르고 싶어요. 나중에 변형을 더 추가해도 무작위로 선택하는 코드를 수정하지 않도록요.
이런 방법을 시도해 봤어요:
Motion.get(randi() % Motion.size())
이것도요:
Motion[randi() % Motion.size()]
둘 다 실패해요. 하나는 Null을 반환하고, 다른 하나는 "Invalid get index '1' (on base: 'Dictionary')."라고 나와요.
실제로 동작하도록 하려면 어떻게 해야 하나요?
영어에서 번역·원문 보기Here's the enum declaration I'm using in GDScript:
enum Motion = { IDLE, STEPPING, DASHING }
I'd like to choose an enum variant randomly without listing every possible variant, allowing me to introduce additional variants later without needing to edit the code that makes the random selection.
Here's one approach I've tried:
Motion.get(randi() % Motion.size())
And another:
Motion[randi() % Motion.size()]
Both fail. One returns Null, while the other reports "Invalid get index '1' (on base: 'Dictionary')."
What's a way of achieving this that will actually work?