Jump to content
Sign in to follow this  

Getting the name of the item participating in the craft.

Recommended Posts

I need to get the item name display.
How to do it right? It gives me an error:
Callframe at: PerformMakeItem
Object tried to call nil in recipe_ recipe name

I have this code:


    item WorkItem1
        Type				=			Normal,
        DisplayName			=		    WorkItem1,
        Icon				=			WorkItem1,
        Weight				=			0.1,

recipe WorkItemExample
        destroy WorkItemqqq,



function recipe_WorkExampleCreat(items, result, player)
    WorkItemName = getPlayer():getInventory():getModData():getDisplayName(getText("IGUI_WorkItem1"));

IGUI_WorkItem is recorded in the IGUI_EN table

You need to iterate over the names from the first list in the recipe.
And save in the variable WorkItemName the name of the IGUI of the object that was used when crafting ...


You need to get the name that I indicated in IGUI_EN


Edited by Nebula

Share this post

Link to post
Share on other sites
Posted (edited)

You must iterate through the list of items that are participating in the craft from the "items" ArrayList<InventoryItem>.



This for loop will iterate through each single item that is participating in the craft.


The if statements will make sure to only give the correct DisplayName that you need for the "WorkItemName" varaible.

I do not know which name you need so you'll have to play with this until you get a desired outcome.

function recipe_WorkExampleCreat(items, result, player)
    for i=0, items:size()-1 do
        local item = items:get(i)
        local itemDisplayName = item:getDisplayName()
        local itemName = item:getName()
    	-- Is "IGUI_WorkItem1" the "itemDisplayName" for the "item" at items:get(i)?
        if itemDisplayName == getText("IGUI_WorkItem1") then
            WorkItemName = itemDisplayName   -- Store item display name into WorkItemName
    	-- Is "IGUI_WorkItem1" the "itemName" for the "item" at items:get(i)?
    	if itemName == getText("IGUI_WorkItem1") then
            WorkItemName = itemName   -- Store item name into WorkItemName


If you need the result item's displayname, then you must use "result:getDisplayName()"

function recipe_WorkExampleCreat(items, result, player)
    WorkItemName = result:getDisplayName()



This is the InventoryItem class with all the methods I used:









Edited by ATPHHe

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...