custom ui + isvalid()

Place to get help with not working mods / modding interface.
drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

custom ui + isvalid()

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

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: custom ui + isvalid()

Post by drs9999 »

push

kovarex
Factorio Staff
Factorio Staff
Posts: 8194
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: custom ui + isvalid()

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

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: custom ui + isvalid()

Post by drs9999 »

Ok thanks, I think I got it working

Post Reply

Return to “Modding help”