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?
|