Page 1 of 1

custom ui + isvalid()

Posted: Sun Aug 11, 2013 10:27 am
by drs9999
I am not sure whether this is a bug or I am just stupid, but here is the problem.
I have this code in the onTick-event:

Code: Select all

if (glob.blueprints.overseer.count + glob.blueprints.miningsites.count) > 0 then
		if ((event.tick % 300) == 0) and (glob.blueprints.overseer.closed == false) then
			if UI.miningsiteOverseerFrame ~= nil then
				if UI.miningsiteOverseerFrame.isvalid() then UI.miningsiteOverseerFrame.destroy() end
			end
			UI.miningsiteOverseer_UI_creation()
		end
	else
		if UI.miningsiteOverseerFrame ~= nil then
			if UI.miningsiteOverseerFrame.isvalid() then UI.miningsiteOverseerFrame.destroy() end
		end 
	end
When I start a new game glob.blueprints.overseer.count + glob.blueprints.miningsites.count == 0
and everything works fine. Later on both variables can be increased and decreased, but each are always >= 0. If at least one variable > 0 everything works fine as well.

But if both are 0 again the UI should be destroyed, instead I got this error:

Code: Select all

111: LuaGuiElementAPI call when gui button does not exist
where line 111 = "if UI.miningsiteOverseerFrame.isvalid() then UI.miningsiteOverseerFrame.destroy() end"

So how can I solve that problem?

Re: custom ui + isvalid()

Posted: Thu Aug 15, 2013 9:25 am
by drs9999
push

Re: custom ui + isvalid()

Posted: Thu Aug 15, 2013 10:34 am
by kovarex
You are right, this is a bug, the isvalid function shouldn't really throw error when it isn't valid :)
It will get fixed (0.7 probably), until that time, you can just set the variable to nil, can't you?

Re: custom ui + isvalid()

Posted: Thu Aug 15, 2013 3:07 pm
by drs9999
Ok thanks, I think I got it working