Thread Tools Display Modes
Prev Previous Post   Next Post Next
03-03-22, 07:35 AM   #1
Firesong
A Deviate Faerie Dragon
Join Date: Jan 2022
Posts: 19
Question Change Button Text on Click Event

Hi all,

I have a button that I want to say "Start" when loaded and then say "Stop" when clicked.

Here is the lua creating the Fontstring and event:
BtnStopGo:SetScript("OnClick", StopStart)
local fs = BtnStopGo:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
fs:SetText("Start")
fs:SetPoint("CENTER")
BtnStopGo:SetFontString(fs)
BtnStopGo.text = fs

And here is the code I tried but it has errors:
function StopStart()
if boolStartStop == true
then
CommandStartStop.texture:SetColorTexture(255,0,0)
boolStartStop = false
fs:SetText("stop")
fs:SetText("Stop")
fs:SetPoint("CENTER")
BtnStopGo:SetFontString(fs)
BtnStopGo.text = fs
else
CommandStartStop.texture:SetColorTexture(0,255,0)
boolStartStop = true
fs:SetText("stop")
fs:SetText("Stop")
fs:SetPoint("CENTER")
BtnStopGo:SetFontString(fs)
BtnStopGo.text = fs
end
end

Here is the Bugsack error message:
"2x Grid\Grid.lua:641: attempt to index global 'fs' (a nil value)"

I've googled a lot and can't find the correct way to have text of a button change on clicking the button. Can anyone help please?
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Change Button Text on Click Event


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off