chargeIDOffset = 5000
function init(me)
	node_setCursorActivation(me, false)
	if getFlag(flag) > 0 then
		charged = true
		id = getFlag(flag)
		if id > chargeIDOffset then
			charged = false
			id = id - chargeIDOffset
		end
		--[[
		if getFlag(chargeFlag) == 0 then
			charged = false
		end
		]]--
		
		orbHolder = getEntityByID(holderID)		
		energyOrb = getEntityByID(id)
		if energyOrb ~=0 and orbHolder ~=0 then
			--debugLog(string.format("%s : setting orb to %d, %d", node_getName(me), entity_x(orbHolder), entity_y(orbHolder)))
			entity_setPosition(energyOrb, entity_x(orbHolder), entity_y(orbHolder))
			if charged then
				entity_setState(energyOrb, STATE_CHARGED)
			end
		end
		if charged then
			door = getEntityByID(doorID)
			if door ~= 0 then
				entity_setState(door, STATE_OPENED)
			end
		end
	end
end

function activate(me)
	if getFlag(flag)==0 or getFlag(flag) >= chargeIDOffset then
		energyOrb = node_getNearestEntity(me, "EnergyOrb")
		if energyOrb ~= 0 then
			if entity_isState(energyOrb, STATE_CHARGED) then
				debugLog("Saving orb in slot, charged")
				setFlag(flag, entity_getID(energyOrb))
				door = getEntityByID(doorID)
				if door ~= 0 then
					entity_setState(door, STATE_OPEN)
				else
					debugLog("COULD NOT FIND DOOR")
				end
			else
				debugLog("Saving orb in slot, not charged")
				setFlag(flag, entity_getID(energyOrb)+chargeIDOffset)				
			end
		else
			debugLog("Could not find orb")
		end
	end
end

function update(me, dt)
end