I have this template within my Chembox {{Molar mass calculator| |Ag ={{{Ag|}}} |As ={{{As|}}} |Au ={{{Au|}}} |B ={{{B|}}} |Ba ={{{Ba|}}} |Bi ={{{Bi|}}} |Br ={{{Br|}}} |C ={{{C|}}} |Ca ={{{Ca|}}} |Cl ={{{Cl|}}} |Co ={{{Co|}}} |Cu ={{{Cu|}}} |F ={{{F|}}} |Fe ={{{Fe|}}} |H ={{{H|}}} |I ={{{I|}}} |K ={{{K|}}} |Li ={{{Li|}}} |N ={{{N|}}} |Na ={{{Na|}}} |Ni ={{{Ni|}}} |O ={{{O|}}} |P ={{{P|}}} |Pt ={{{Pt|}}} |S ={{{S|}}} |Se ={{{Se|}}} |Sr ={{{Sr|}}} |Zn ={{{Zn|}}} }} as each of these element parameters are optional they can be null and even when some parameters are provided I get the script error:
Lua error in Module:Molar_mass_calculator at line 8: attempt to perform arithmetic on a nil value.
Backtrace:
1. *(tail call)*: ? 2. *Module:Molar_mass_calculator:8 http://localhost/mediawiki/index.php?title=Module:Molar_mass_calculator&action=edit#mw-ce-l8*: in function "chunk" 3. *mw.lua:497*: ? 4. *(tail call)*: ? 5. *[C]*: in function "xpcall" 6. *MWServer.lua:87*: in function "handleCall" 7. *MWServer.lua:301*: in function "dispatch" 8. *MWServer.lua:58*: ? 9. *(tail call)*: ? 10. *mw.lua:141*: ? 11. *Module:Infobox:320 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l320*: in function "preprocessArgs" 12. *Module:Infobox:373 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l373*: in function "chunk" 13. *mw.lua:497*: ? 14. *(tail call)*: ? 15. *[C]*: in function "xpcall" 16. *MWServer.lua:87*: in function "handleCall" 17. *MWServer.lua:301*: in function "dispatch" 18. *MWServer.lua:40*: in function "execute" 19. *mw_main.lua:7*: in main chunk 20. *[C]*: ?
any ideas of how to overcome this error?
On 1/04/2015 7:28 PM, Ricordisamoa wrote:
To get parameters passed to the template, just call :getParent() in the module: example https://test2.wikipedia.org/wiki/Special:Diff/155912
Il 01/04/2015 11:13, Brenton Horne ha scritto:
Thanks for this. What should /Template:Molar mass calculator/ look like? Currently I have:
{{#invoke:Molar mass calculator|calc}}
but this returns a null value when variables are provided.
On 1/04/2015 12:44 PM, Ori Livneh wrote:
On Tue, Mar 31, 2015 at 3:25 PM, Brenton Horne brentonhorne77@gmail.com wrote:
Thanks, I have also posted this question on Stackoverflow ( http://stackoverflow.com/questions/29377097/lua-module- for-calculating-the-molar-mass-of-chemical-compounds) someone with Lua skills but not so much with MediaWiki Lua templating and they gave this code:
|local AtomicWeightLookup= { C= 12.01, H= 1.001, O= 16 }
local function Calculate(Input) -- Input Example: {C = 2, H = 6, O = 1} local Result= 0 -- Iterate through Input table for Element,Quantityin next,Inputdo -- If element is not found in table, assume 0 weight. local AtomicWeight= AtomicWeightLookup[Element] or 0 -- Multiply Result= Result+ Quantity* AtomicWeight end return Result end
-- EXAMPLE print(Calculate({C= 2, H= 6, O= 1}))|
but as you can see there's no variables in here that are set by MediaWiki templates, but it seems like a decent starting place.
Here you go: https://test2.wikipedia.org/wiki/Module:Standard_atomic_weight https://test2.wikipedia.org/wiki/Module:Molar_mass_calculator demo: https://test2.wikipedia.org/wiki/Module_talk:Molar_mass_calculator
Note that your table had an error -- the atomic weight of Fluorine is assigned to symbol 'C' rather than 'F'. _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l