templatesluamodulemediawiki-apiwikia

I am attempting to pass an infobox value into a LUA module that outputting an answer based on the infobox value (FANDOM WIKIA)


I am working on a module that converts the value of a specific value into a new value when mutliplying it by a certain percentage. EX 100 * 1.3754 = 137.54. When I use the module, it spits out my debug error, saying that it received '1150' in the case that I will link. I've asked on reddit several times now, even asked Fandom support, but no one has been successful. I've been working on this for almost 9 hours in total now, and I've gotten close, but I am still so 'far'. I will paste the most well worded request I've put below:

local p = {}

function p.calculateAlchValue(frame)
    local shop_value_str = frame.args[1] or ""
    local shop_value = tonumber(shop_value_str)

    
-- Check if the conversion was successful
    if not shop_value then
        return "Error: Invalid or missing shop_value. Received: " .. tostring(shop_value_str)
    end

    local percentage = 1.3754
    local result = math.ceil(shop_value * percentage)

    return tostring(result)
end

return p

This isn't working, everytime I enter a value that uses dynamic values aka shop_value, it displays the error as: Error: Invalid or missing shop_value. Received: 1150

When I open the visual editor, I get the actual answer of 1582. But only in the visual editor...

If I send the code:

{{Item
| Item name = {{PAGENAME}}
| Item Image = [[File:{{PAGENAME}}.png]]
| tradeable = Yes
| stackable = No
| examine = It is a(n) {{PAGENAME}}.
| shop_value = 1150
| alch_value = {{#invoke:CalcAlchValue|calculateAlchValue|1150}}
| noteable = Yes
}}

It returns the correct value of 1582.

The code I'm using on the page:

{{Item
| Item name = {{PAGENAME}}
| Item Image = [[File:{{PAGENAME}}.png]]
| tradeable = Yes
| stackable = No
| examine = It is a(n) {{PAGENAME}}.
| shop_value = 1150
| alch_value = {{#invoke:CalcAlchValue|calculateAlchValue|{{{shop_value}}}}}
| noteable = Yes
}}

If anyone knows how to fix any of this, I've reached out to different sub-reddits, and even fandom support, used GPT to help, but nothing has worked so far.

Links to the fandom pages: https://remote-realms.fandom.com/wiki/Module:CalcAlchValue | https://remote-realms.fandom.com/wiki/Palatine_ore


Solution

  • So, I finally figured it (not myself, but another user on the fandom discord server) basically, the way I am trying to #invoke the template on the page of the item, needs to be invoked by default in the Template:Item. So I was able to change the default to

     <data source="alch_value"><label>Chrysopoeia Value</label><default>{{#invoke:CalcAlchValue|calculateAlchValue|{{{shop_value}}}}}</default></data>
    

    Doing it inside the Template:Item itself, magically fixed the issue. Gotta love AI not knowing how to do stuff all the way ^^