Retrieve the UIName of an entity that doesn't exist

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Retrieve the UIName of an entity that doesn't exist

Post by cromcrom »

hello there.
I am puzzled, because, for my crafting script, I am trying, for the info panel, to show the UIName of an object .
this is part of the code below:

Code: Select all

	local component1 = Item.comp1
	local componentNumber1 = Item.compnum1
	local component2 = Item.comp2
	local componentNumber2 = Item.compnum2
	local component3 = Item.comp3
	local componentNumber3 = Item.compnum3
	local skillLevel = cromlibrary.script.checkSkillLevel(craftrequired)
	local skillLevelName = cromskills.script.translateLevel(skillLevel)
	local itemcraftingexpertise = ""
	local bonus = 0
	local itemKnowledgeVar = itemtocraft.."_craftXP"
		if cromvar.script.getVar(itemKnowledgeVar) == nil then 
		cromvar.script.setVar(itemKnowledgeVar,0)
		--print(itemKnowledgeVar)
		else
		bonus,itemcraftingexpertise = returnCraftingExpertise(itemtocraft)
		end
	local craftingSummaryText = "Craft a "..itemName..";Difficulty = "..difficulty..";Skill level= ".. skillLevelName .. " ".."Item Knowledge= "..itemcraftingexpertise.."; Major Attribute= "..majorAttribute..";Minor Attribute= "..minorAttribute.." ".."Need: "..componentNumber1.." ".. component1
my recipes are stored in a table (Item).
calling Item.comp1 returns me a string storing the name of the needed component.

I tried to get the UIName from this string, but has this object is not created yet, I can't call a findEntity, for example.
I tried all matters of
component1.go.item:getUiName(), with all variations on this subject, to no avail.
I think the problem is that the game doesn't identify this string as the name of an object.

Any ideas please ?
A trip of a thousand leagues starts with a step.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Retrieve the UIName of an entity that doesn't exist

Post by AndakRainor »

I had a similar problem when I needed some info on spells. As they are definitions and not actual GameObjects, I did not find any way in the scripting reference to access those definitions' details.

So I used this solution: I put all the spells definitions in a table and loop through it on initialization to call the define function on all elements of this table. This way I am sure the table and the definitions are strictly the same, and I have a table available to get any value I need about those definitions.

You could do the same with all items, or at least those you need in your crafting system.
Last edited by AndakRainor on Sat Jul 04, 2015 11:09 am, edited 1 time in total.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Retrieve the UIName of an entity that doesn't exist

Post by cromcrom »

Sounds good, thanks for the tip.
A trip of a thousand leagues starts with a step.
Post Reply