Reputation: 25
EDIT: This is GDScript, not sure if that is obvious or not.
I’m a hobbyist learning GDScript for Godot 3.1.
I am just trying something out, and I cannot understand why my code throws this error:
ubMyAge is not declared in this scope.
It occurs in the func _on_GenerateUnboundAttributes_pressed(): part of the code just at the bottom.
The error even occurs if I put it in the generate_age() function. What am I missing?
Thanks for your time!
extends Node
var _rng = RandomNumberGenerator.new()
# physical attributes
onready var dexLabel = $Control/AttrPanel/PhysColor/PhysGrid/DexLabel
onready var fortLabel = $Control/AttrPanel/PhysColor/PhysGrid/FortLabel
onready var strLabel = $Control/AttrPanel/PhysColor/PhysGrid/StrLabel
onready var swfLabel = $Control/AttrPanel/PhysColor/PhysGrid/SwfLabel
# mind attributes
onready var engLabel = $Control/AttrPanel/MindColor/MindGrid/engLabel
onready var mndLabel = $Control/AttrPanel/MindColor/MindGrid/mndLabel
onready var preLabel = $Control/AttrPanel/MindColor/MindGrid/preLabel
onready var sorLabel = $Control/AttrPanel/MindColor/MindGrid/sorcLabel
#resistances
onready var anuLabel = $Control/AttrPanel/ResistColor/MindGrid/anuLabel
onready var rilLabel = $Control/AttrPanel/ResistColor/MindGrid/rilLabel
onready var resLabel = $Control/AttrPanel/ResistColor/MindGrid/resLabel
# feedback
onready var trtLabel = $Control/Feedback/FeedbackLight/FeedbackGrid/trtLabel
onready var myageLabel = $Control/Feedback/FeedbackLight/FeedbackGrid/myageLabel
# Unbound Monster Vairables
var ubMyAge = 0
var ubTraitsAllowed = 0
# Unbound Monster Factors & Associated
var minAge = 1
var maxAge = 50
var ubAgeFactor = 10 # every 10 years, gain 1 trait
# initialize and declare attributes
var dexterity = 0
var fortitude = 0
var strength = 0
var swiftness = 0
var energy = 0
var mind = 0
var precision = 0
var sorcery = 0
var annulment = 0
var resilience = 0
var resistance = 0
func _ready():
randomize()
label_populate()
func label_populate():
dexLabel.text = str(dexterity)
fortLabel.text = str(fortitude)
strLabel.text = str(strength)
swfLabel.text = str(swiftness)
engLabel.text = str(energy)
mndLabel.text = str(mind)
preLabel.text = str(precision)
sorLabel.text = str(sorcery)
anuLabel.text = str(annulment)
rilLabel.text = str(resilience)
resLabel.text = str(resistance)
func generate_age():
ubMyAge = _rng.randi_range(minAge, maxAge)
print("This is my age " + str(ubMyAge))
if ubMyAge >= 20:
ubTraitsAllowed = ubMyAge / ubAgeFactor
print("This is what happens when ubMyAge is >= 20. I have this many Traits: " + str(ubTraitsAllowed))
else:
ubTraitsAllowed = 2
print("This is what happens when ubMyAge is < 20. I have this many Traits: " + str(ubTraitsAllowed))
func _on_GenerateUnboundAttributes_pressed():
generate_age()
**myageLabel.text = str(ubMyage)**
trtLabel.text = str(ubTraitsAllowed)
Upvotes: 0
Views: 729