0

编辑:这是 GDScript,不确定这是否明显。

我是一个为 Godot 3.1 学习 GDScript 的爱好者。

我只是在尝试一些东西,但我不明白为什么我的代码会抛出这个错误:

ubMyAge 未在此范围内声明。

它出现在 func _on_GenerateUnboundAttributes_pressed(): 代码的底部部分。

如果我把它放在 generate_age() 函数中,甚至会发生错误。我错过了什么?

谢谢你的时间!

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)
4

1 回答 1

2

你拼错ubMyAgeubMyage

于 2019-12-04T14:29:12.870 回答