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? |
Code:
local button = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate") The most probable cause is that fs does not exist inside StopStart because it is defined as a local in another scope. |
Thanks. That is so much more elegant than my effort as well as working!
|
All times are GMT -6. The time now is 11:38 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI