Jump to content

Recognize prefab name


Cyde042

Recommended Posts

Just so I don't need to make individual files just because of 1 line. I want the function to recognize and set the correct prefab.

local function pouchablefn(inst)	inst.components.pickable.ontransplantfn = ontransplantfn		inst:AddComponent("pouchable")	inst.components.pouchable:SetUp("dug_"..prefab.name"") --I think it has to be something like this but I can't make it workend

So this function is loaded after to the cave_banana_tree prefab it is initialized. And according to the prefab the function is loaded to, the SetUp product will change, so it will be "dug_cave_banana_tree". I hope I made it clear what I'm having trouble with.

Link to comment
Share on other sites

Just so I don't need to make individual files just because of 1 line. I want the function to recognize and set the correct prefab.

local function pouchablefn(inst)	inst.components.pickable.ontransplantfn = ontransplantfn		inst:AddComponent("pouchable")	inst.components.pouchable:SetUp("dug_"..prefab.name"") --I think it has to be something like this but I can't make it workend

So this function is loaded after to the cave_banana_tree prefab it is initialized. And according to the prefab the function is loaded to, the SetUp product will change, so it will be "dug_cave_banana_tree". I hope I made it clear what I'm having trouble with.

 

Think it should be inst.name in this case.

Also all dug items are spearte prefabs they are buried somewhere in the prefab folder, so you can just set the product to your other prefab.

("dug_"..inst.name)

The name thing is case sensitive, it will be the string name rather than prefab name.

Link to comment
Share on other sites

Think it should be inst.name in this case.

Also all dug items are spearte prefabs they are buried somewhere in the prefab folder, so you can just set the product to your other prefab.

("dug_"..inst.name)

The name thing is case sensitive, it will be the string name rather than prefab name.

 

I'm having trouble. I tried seeing what name print gives me and it's dug_Cave Banana Tree. So I tried changing all the values to that, but not even the prefab worked. I think because of the spaces.

 

I had another idea, in the kramped component, a data.victim is used to determine the prefab name and not the string. Any way to use that method?

Link to comment
Share on other sites

I'm having trouble. I tried seeing what name print gives me and it's dug_Cave Banana Tree. So I tried changing all the values to that, but not even the prefab worked. I think because of the spaces.

 

I had another idea, in the kramped component, a data.victim is used to determine the prefab name and not the string. Any way to use that method?

 

You trying to make banna trees digable like berry bushes?

If so you just need to make new prefab for them, and then just put that prefab name in that function.

or just use inst alone, can't rember if that was giving the name to

Link to comment
Share on other sites

You trying to make banna trees digable like berry bushes?

If so you just need to make new prefab for them, and then just put that prefab name in that function.

or just use inst alone, can't rember if that was giving the name to

 

I know that, I already had the prefab made and working, but I plan on having not only the banana trees dig-able, so wouldn't it be less resource-hungry if I use only one function for like ~5 pickers instead of 5:5?

Link to comment
Share on other sites

I know that, I already had the prefab made and working, but I plan on having not only the banana trees dig-able, so wouldn't it be less resource-hungry if I use only one function for like ~5 pickers instead of 5:5?

 

Its less code for sure, but recource wise its not a big difference if you have 1 or 5 functions, they are not called at the same time anyway, and memory usage is minimal.

Since you can easly take normal prefab name you can just hardcode the if statement for all 5 of them

if inst.name =="Cave Banana Tree" then

your dug setup here

elseif inst.name == "Something"

next gug prefab setup

...

and so on.

 

Link to comment
Share on other sites

Its less code for sure, but recource wise its not a big difference if you have 1 or 5 functions, they are not called at the same time anyway, and memory usage is minimal.

Since you can easly take normal prefab name you can just hardcode the if statement for all 5 of them

if inst.name =="Cave Banana Tree" then

your dug setup here

elseif inst.name == "Something"

next gug prefab setup

...

and so on.

 

 

 Hmm, didn't think to use string names. Thanks

Link to comment
Share on other sites

Its less code for sure, but recource wise its not a big difference if you have 1 or 5 functions, they are not called at the same time anyway, and memory usage is minimal.

Since you can easly take normal prefab name you can just hardcode the if statement for all 5 of them

if inst.name =="Cave Banana Tree" then

your dug setup here

elseif inst.name == "Something"

next gug prefab setup

...

and so on.

 

 

Actually I there's another thing, do you know of a way to determine if something is planted in the caves or above ground?

Link to comment
Share on other sites

Actually I there's another thing, do you know of a way to determine if something is planted in the caves or above ground?

 

I can faintly remember that there are two ways to do this, one is something about GetWorld() "type", the other about the topology level.

 

I think GetWorld():HasTag("cave") or something along those lines may work.

 

EDIT: GetWorld() actually has a cave tag... That was easy.

Link to comment
Share on other sites

I can faintly remember that there are two ways to do this, one is something about GetWorld() "type", the other about the topology level.

 

I think GetWorld():HasTag("cave") or something along those lines may work.

 

EDIT: GetWorld() actually has a cave tag... That was easy.

 

Okay, it worked, but now I ran into something else. Is it possible to replace the animation asset a prefab is using? Or do I have to edit the current asset and add more builds?

function lichenfn(inst)	if not GLOBAL.GetWorld():HasTag("cave") thenlocal assets={	-- Asset("ANIM", "anim/grass.zip"),	Asset("ANIM", "anim/algae_bush2.zip"), --This is different	Asset("SOUND", "sound/common.fsb"),}endend

I tried this and it doesn't work. I don't know how to make the game use the other asset.

 

Link to comment
Share on other sites

Okay, it worked, but now I ran into something else. Is it possible to replace the animation asset a prefab is using? Or do I have to edit the current asset and add more builds?

I tried this and it doesn't work. I don't know how to make the game use the other asset.

 

Every prefab only loads the assets it specifies. (the MemSpikeFix mod unloads them when unused, btw)

 

Add the required assets to your assets table. If the required assets aren't consistant, you can try some table.insert() witchery, but I am not sure if it works after the game loaded. I only ever did that in OnLoad, in Questastic.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...