mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
e338cf1c47
Built a simple UI to test out the dice roller. Can handle multiple die and supports D4, D6, D8, D10, D12, and D20 (Let me know if there shouldn't be a restriction on the valid types of die).
39 lines
815 B
GDScript
39 lines
815 B
GDScript
#Die class
|
|
|
|
extends Button
|
|
|
|
class_name Die
|
|
|
|
#array of valid number of faces
|
|
var dieTypes = [4, 6, 8, 10, 12, 20]
|
|
|
|
#value of selected die type
|
|
var numFaces: int
|
|
|
|
#bool will be used to check if a valid die type was chosen
|
|
var validNumFaces = false
|
|
|
|
#Class constructor
|
|
func _init(value):
|
|
numFaces = value
|
|
|
|
#returns an integer value of the rolled result (assuming the die is a valid type)
|
|
func rollDie():
|
|
randomize()
|
|
|
|
#check if selected die type exists in dieTypes array
|
|
for value in dieTypes:
|
|
if value == numFaces:
|
|
validNumFaces = true
|
|
|
|
#if the selected die type exists, we can roll an integer value based on the number of sides.
|
|
if validNumFaces:
|
|
var rolledNum
|
|
rolledNum = randi() % numFaces + 1
|
|
return rolledNum
|
|
else:
|
|
print("You do not have a valid number of sides on the die!")
|
|
return
|
|
|
|
|