Invisible, Inc.

Invisible, Inc.

Not enough ratings
rjParams
   
Award
Favorite
Favorited
Unfavorite
mod
File Size
Posted
Updated
39.060 KB
19 Jun @ 6:36pm
20 Jun @ 1:34pm
2 Change Notes ( view )

Subscribe to download
rjParams

Description
A modder's resource, open for general use.

This mod provides sleek low-code methods for mod cross-talk, smoothing out the syntax and creating a new table for shared parameters.

My mods utilize this to manage shared sentinel values with greater convenience. Extensive inline documentation is included in the mod's rjParams.lua. Feel free to use it in your mods if you wish. Enjoy!

I don't plan to ever fundamentally change this, for the sake of reliability for the integrated mods. New methods? Maybe. Changes to public methods' existing names, args, or returns? Never.

[for mod makers] How to use the mod:
-- modinit.lua example local function load( modApi, options, params ) local scriptPath = modApi:getScriptPath() -- Retrieve rjParams for cross-mod option-accessible shared params local rjParams = mod_manager:getRjParams() --unlike params, rjParams are declared on both save load & campaign generation -- Publish a sentinel for other listeners (BTW: Any rjParam set in load - even via getParam - is propagated to params.rjParams, too!) -- NOTEWORTHY: Please don't modify another's sentinel values without their collaboration. This could cause inadvertent effects for subs. -- IMPORTANT: This is a shared space, so be specific! Use a special prefix that's unique to you. Don't use generic terms. rjParams:setParam( "RS_SentinelTP2", someValue ) -- Check a sentinel from another mod (2nd arg is an optional default & is returned if the rjParam is nil) if rjParams:getParam( "RS_SentinelTP2", false ) then -- do something end -- Do something if we got to this shared sentinel value first (3rd arg is an optional "set to default if rjParam nil?") if rjParams:getParam( "RS_QR1Stringmod", modApi.mod_id, true ) == modApi.mod_id then -- we got here first, so do something about it -- Other mods with this line won't get here, since our getParam(name, defaultValue, true) set the param end -- Get another mod's option with sleek and readable syntax and an optional fallback default local dummyOption = { enabled = false } -- we get this if the save lacks our friend's option local friendsOption = rjParams:getModOption( friendsModName, friendsOptionName, dummyOption ) -- do stuff with friendsOption -- Get ALL options from another mod with sleek and readable syntax and an optional fallback default local dummyOptions = { friendsOptionName = { enabled = false } } -- we get this if the save lacks our friend's mod local friendsOptions = rjParams:getModOptions( friendsModName, dummyOptions ) -- do stuff with friendsOptions -- Retrieve another mod's modData (why would you need this? well, it's here if you do.) local friendsModData = rjParams:getModData( "Lock Decoder Redux" ) -- do stuff with friendsModData. FYI: friendsModData.options is that mod's options -- Check if the player has our required rjParams version local requiredRjParamsVersion = 1.1 if rjParams:versionIsLessThan( requiredRjParamsVersion ) then log:write( "Features [x], [y], [etc] are disabled. To restore, upgrade to rjParams v" .. requiredRjParamsVersion ) end -- Get all the rjParams (I don't know why you'd want to, but why not?! lol) local _rjParams = rjParams:getParams() -- do stuff with _rjParams end -- Function append example (rjParams from sim-accessible scopes) -- FYI: rjParams can be set on load with access to the save's options, creating a link to this space -- FYI: rjParams that are set in load upon starting a campaign also propagate to difficultyOptions.rjParams -- automatically propagate to sim's difficultyParam's rjParams key. This is done by injecting into params a pointer to rjParams._params. local use_stim = util.extend( oldUse_stim ) { doInjection = function( self, sim, unit, userUnit, targetUnit, ...) -- Direct access (preferred probably) -- NOTEWORTHY: These are the live rjParams params & aren't tied to the campaign. local rjParams = mod_manager:getRjParams() if rjParams == nil then log:write( "Feature [x] is disabled due to missing rjParams dependency" ) end -- do stuff with rjParams:getParam(myParamName) -- Indirect access (fallback method for when mod_manager inaccessible) -- NOTEWORTHY: Here, _rjParams were cached on campaign generation. local _rjParams = unit:getSim():getParams().difficultyOptions.rjParams if _rjParams == nil then log:write( "Feature [x] is disabled due to missing rjParams dependency" ) end -- do stuff with _rjParams[myParamName] end end