Page 1 of 1

Interface not visible RESOLVED

Posted: Sat Jul 09, 2016 7:04 pm
by Ranakastrasz
I am not sure If I am doing this right. Based off of Treefarm lite, and growable fertilizer.
I suspect that the On_Init part isn't working, but manually calling doesnt work either.

Code: Select all

/c     remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "fusion" ,"fuelled","fusion-reactor-mk4-equipment"   ,11760 * 1000)  

Code: Select all

module(..., package.seeall)

remote.add_interface("ranamods_modular_armor_interface",
{
    registerEquipmentGroup = registerEquipmentGroup(iName,iType)
        registerEquipmenetGroup(iName,iType)
	end,
    registerEquipmentPrototype = registerEquipmentPrototype (iName,iType,iPrototype,iPower)
        registerEquipmentPrototype(iName,iType,iPrototype,iPower)
	end,
    registerFuelPrototype = registerFuelPrototype (iName,iType,iPrototype,iPower)
        registerFuelPrototype(iName,iType,iPrototype,iPower)
	end


}
)

Code: Select all

function registerEquipmentGroup(iName,iType)
    if not RanaMods.ModularArmor.equipmentData then
        RanaMods.ModularArmor.equipmentData = {}
    end
    for _, v in pairs(RanaMods.ModularArmor.equipmentData) do
        if v.name == iName then
            return
        end
    end
    table.insert(RanaMods.ModularArmor.equipmentData, {name=iName, type = iType})
    globalPrint(iName.." "..iType)
end

function registerEquipmentPrototype (iName,iType,iPrototype,iPower)

    if not RanaMods.ModularArmor.equipmentData then
        RanaMods.ModularArmor.equipmentData = {}
    end
    for _, v in pairs(RanaMods.ModularArmor.equipmentData) do
        if v.name == iName then
            if not v.equipment then
                v.equipment = {}
            end
            
            table.insert(v.equipment, {name=iPrototype, power=iPower * RanaMods.ModularArmor.config.powerCoef *RanaMods.ModularArmor.config.secondsPerTick})
            
            break
        end
    end
end

function registerFuelPrototype (iName,iType,iPrototype,iPower)

    if not RanaMods.ModularArmor.equipmentData then
        RanaMods.ModularArmor.equipmentData = {}
    end
    for _, v in pairs(RanaMods.ModularArmor.equipmentData) do
        if v.name == iName then
            if not v.fuel then
                v.fuel = {}
            end
            
            table.insert(v.fuel, {name=iPrototype, power=iPower*RanaMods.ModularArmor.config.fuelCoef})
            
            break
        end
    end
end

Code: Select all

function register_Equipment()
    --remote.call("ranamods_modular_armor_interface", "registerEquipmentGroup", "conduit","conduit")
    --remote.call("ranamods_modular_armor_interface", "registerEquipmentGroup", "burner","fuelled")
    --remote.call("ranamods_modular_armor_interface", "registerEquipmentGroup", "fusion","fuelled")
    
    --remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "conduit","conduit","power-conduit-equipment"    , 40 * 1000)
    remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "conduit","conduit","power-conduit-mk2-equipment", 40 * 1000)
    remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "conduit","conduit","power-conduit-mk3-equipment", 40 * 1000)
    remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "conduit","conduit","power-conduit-mk4-equipment", 40 * 1000)
    
    --remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "burner" ,"fuelled","engine-equipment"               ,100 * 1000)
    remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "burner" ,"fuelled","engine-mk2-equipment"           ,150 * 1000)
    remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "burner" ,"fuelled","engine-mk3-equipment"           ,250 * 1000)
    remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "burner" ,"fuelled","engine-mk4-equipment"           ,400 * 1000)
                                                                                                      
    --remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "fusion" ,"fuelled","fusion-reactor-equipment"       ,  960 * 1000)
    remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "fusion" ,"fuelled","fusion-reactor-mk2-equipment"   , 2250 * 1000)
    remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "fusion" ,"fuelled","fusion-reactor-mk3-equipment"   , 5400 * 1000)
    remote.call("ranamods_modular_armor_interface", "registerEquipmentPrototype", "fusion" ,"fuelled","fusion-reactor-mk4-equipment"   ,11760 * 1000)
    
    --remote.call("ranamods_modular_armor_interface", "registerFuelPrototype", "fusion" ,"fuelled","fusion-reactor-mk4-equipment"   ,11760 * 1000)
    
    
end
script.on_init(function()
	if (remote.interfaces.ranamods_modular_armor_interface) and
       (remote.interfaces.ranamods_modular_armor_interface.registerEquipmentGroup) and
       (remote.interfaces.ranamods_modular_armor_interface.registerEquipmentPrototype) and
       (remote.interfaces.ranamods_modular_armor_interface.registerFuelPrototype) then
        register_Equipment()
		if errorMsg ~= nil then
			for _, player in ipairs(game.players) do
				player.print(errorMsg)
			end
		end
	end
end)
Old

Re: Mod load Order or Global references

Posted: Sat Jul 09, 2016 11:44 pm
by DaveMcW
data.lua is global, control.lua is not.

Re: Mod load Order or Global references

Posted: Sun Jul 10, 2016 12:04 am
by Ranakastrasz
Those are in config.lua files, both of which are required by their corresponding data.lua files.

Edit:
Oh, I see. It was in the data file in the first place.
Now I have to hope the control.lua file can see what is defined in data.lua, and functions can be setup there as well.

Edit: No, after data is setup, Control can't access the settings setup there.


How Do you go about having global config data, accessable in the Control.lua, which can be altered by both mods?

Re: Mod load Order or Global references

Posted: Sun Jul 10, 2016 9:40 am
by orzelek
You could define the config in one mod and add remote interface in there to return that config.
Then in dependant mod you can call the remote and use config data.

Re: Mod load Order or Global references

Posted: Sun Jul 10, 2016 9:51 am
by Ranakastrasz
Can you point me at a mod that uses those?

Re: Mod load Order or Global references

Posted: Sun Jul 10, 2016 10:09 am
by orzelek
Ranakastrasz wrote:Can you point me at a mod that uses those?
RSO defines some but doesn't use them - they are meant for calling from console.
Treefarm might have some that are used in code of it's addons for new seeds interface.

Re: Mod load Order or Global references

Posted: Sun Jul 10, 2016 11:25 am
by Ranakastrasz
That looks like exactly what I want. Thanks.
Edit: actually, how did bobs mod do it? It works, and I based my adaptions on it.

Re: Mod load Order or Global references

Posted: Sun Jul 10, 2016 1:48 pm
by orzelek
Ranakastrasz wrote:That looks like exactly what I want. Thanks.
Edit: actually, how did bobs mod do it? It works, and I based my adaptions on it.
Bob's mods have no script so it uses the fact that data side is shared.