每当我尝试在robloxian lua中执行这组代码时,就无法访问文本框。这段代码是执行此操作的前提,但是我认为它代替了访问文本框内文本的属性。这是我正在使用的代码的某种代表。因此,可以说鲍勃想和约翰说话。我会这样写。
game.StarterGui.ScreenGui.Frame.JohnsSpeech.Text = game.StarterGui.ScreenGui.Frame.JohnsUserSetText.Text
现在,JohnsUserSetText是文本框,JohnsSpeech是语音。但是,当我尝试执行此操作时,它不起作用。它只是说出属性中的任何文本。任何帮助,将不胜感激。谢谢!祝您度过愉快的一天!
就像齐根霍恩(M. Ziegenhorn)所说的那样,您的问题是,您指的是StarterGui,而不是PlayerGui。
StarterGui是包含默认GUI的容器,该默认GUI将在生成时分发给玩家,而PlayerGui(例如game.Players.Ravenshield.PlayerGui)是为每个玩家存储GUI的位置。只能通过LocalScript访问PlayerGui。
访问PlayerGui的最简单方法显然是将LocalScript放入正在使用的ScreenGui中。否则,您也可以通过执行game.Players.LocalPlayer.PlayerGui轻松访问它
如果我将LocalScript直接放到我们正在使用的ScreenGui中,它可能看起来像这样:
local TextBox = script.Parent.TextBox
local SpeechLabel = script.Parent.SpeechLabel
SpeechLabel.Text = TextBox.Text
但是,您可能希望在他们将文本写入TextBox时添加文本。然后,我们需要看一下ROBLOX的文档,尤其是TextBox Object。
如果向下滚动到“事件”,则可以查看TextBox.Changed事件。每当TextBox的属性更改时,都会触发该事件。我们还可以使用TextBox.FocusLost,它在客户端使TextBox失去焦点时触发。该事件提供了一个布尔值“ enterPressed”,该值告诉我们客户是否按回车键来失去焦点。
local TextBox = script.Parent.TextBox
local SpeechLabel = script.Parent.SpeechLabel
TextBox.FocusLost:Connect(function(enterPressed)
if enterPressed then -- Checking if the enterPressed is true and not nil
-- The user must have pressed enter to exit the TextBox.
-- Could mean that they're done writing something.
SpeechLabel.Text = TextBox.Text
end
end)
所有事件都必须使用:Connect方法来绑定。这就是告诉ROBLOX开始“监听”该事件,以确保该函数在每次发生时都触发。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句