Skip to content

Instantly share code, notes, and snippets.

@willnationsdev
Created August 27, 2019 19:07
Show Gist options
  • Save willnationsdev/fff061379c3e6b9b6c8b54001a596eca to your computer and use it in GitHub Desktop.
Save willnationsdev/fff061379c3e6b9b6c8b54001a596eca to your computer and use it in GitHub Desktop.
Examples of exporting integers in Godot to generate GUI elements
# enum - generates radio buttons
enum {
SUIT_HEARTS,
SUIT_DIAMONDS,
SUIT_SPADES,
SUIT_CLUBS
}
export(int, "Hearts", "Diamonds", "Spades", "Clubs") var suit := SUIT_HEARTS
# flag enum - generates checkboxes
enum {
TYPE_FIRE = 1,
TYPE_ICE = 2,
TYPE_WIND = 4,
TYPE_EARTH = 8
}
export(int, FLAG, "Fire", "Ice", "Wind", "Earth") var dmg_type = TYPE_FIRE | TYPE_ICE
# procedurally generate the PropertyInfo settings from a Dictionary mapping
tool
extends Node
enum {
SUIT_HEARTS,
SUIT_DIAMONDS,
SUIT_SPADES,
SUIT_CLUBS
}
const SuitNames := {
SUIT_HEARTS: "Hearts",
SUIT_DIAMONDS: "Diamonds",
SUIT_SPADES: "Spades",
SUIT_CLUBS: "Clubs"
}
var suit := SUIT_HEART
func _get_property_list() -> Array:
return [
{
"name": "suit",
"type": TYPE_INT,
"hint": PROPERTY_HINT_ENUM,
"hint_string": PoolStringArray(SuitNames.values()).join(",")
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment