Jump to content

Recommended Posts

It still crashes, it seems i probably wrote something wrong that is making the game crash, especifically i seems to be ''inst.components.machine:IsOn()'', i'm doing something wrong there, i'm sure. I wish it showed a error message or something, to see what is wrong there.Also, making a mod instead of simply staring at the code has made me learn a lot on how to the game works, it's amazing.

Yeah, I was going to say it was maybe something to do with IsOn(), maybe that the machine component wasn't loaded but then I noticed the syntax error. The problem with the else is the "end" that closes the function might be interpreted as the "end" that closed the if, and subsequent funtions would be defined in the scope of that function, and then you have all sorts of problems. Maybe the interpreter handles that more gracefully than I give it credit for, but it was an easy error. The thing is, the sanityup function doesn't look like it ever gets called. It's a local function, so nothing else is going to call it, and it's not called by your code posted anywhere, so I can't see IsOn() causing a runtime issue because it's never running.

local function sanityup(inst)	FindNearestEntityWithTag("phonograph1")	if inst.components.machine:IsOn() then		inst.components.sanityaura.aura = -TUNING.SANITYAURA_SMALL	endend
Should be this really. I don't know if when you tried to fix it maybe you just removed the else without replacing it with an end, which would cause the same problem.Also, I'm confused by your play and stop functions, play removes the playerprox component, but nothing adds it. playerprox is a component that gives some functionality to do something when the player gets near the entity. It works by scheduling a task to poll for the player's relative distance, and on noticing the player is within certain bounds, it triggers a function. In the snippet I provided, the component runs inst.components.machine:TurnOn() when you get near.Looking at maxwellphonograph.lua, I see where you got your play and stop functions. In the case of maxwellphonograph, when you start playing the record, it removes the playerprox component because it doesn't want to listen for the player's comings and goings any more. It doesn't stop playing until the player destroys it or turns it off.It doens't hurt that it's still there because it tests for the component before trying to remove it, but I think it's useful to realize how it works. You would also need something to tell the prefab when to start applying the sanity aura. The way I'd recommend learning this is think about other prefabs that manipulate sanity. The first thing that comes to mind is a night light, but it varies based on flame level and distance, so that's complicated. Next I'd check evil flowers, but they're too simple, they just define an aura value, but you want a function to check whether the machine is on. Next I'd check pigs, because while they move around, they are still a prefab, they still change sanity based on different conditions.
--in function common():inst:AddComponent("sanityaura")inst.components.sanityaura.aurafn = CalcSanityAura--as CalcSanityAura:local function CalcSanityAura(inst, observer)	if inst.components.werebeast       and inst.components.werebeast:IsInWereState() then		return -TUNING.SANITYAURA_LARGE	end		if inst.components.follower and inst.components.follower.leader == observer then		return TUNING.SANITYAURA_SMALL	end		return 0end
You would do the same thing for yours. Add an aurafn to inst.components.sanityaura pointing to sanityup. You might as well use your sanityup function to do this:
local function sanityup(inst, observer)        -- -- I've added the observer parameter to the function, it gets passed by the sanityaura component so I figured it's worth         -- -- leaving in.  It is worthwhile if you are testing for the player's distance, or other player aspects. 	-- FindNearestEntityWithTag("phonograph1")        -- -- Remove the above line, there's no reason to find the nearest entity with tag phonograph.  You're writing a function that        -- -- is only being run by the phonograph's own 	if inst.components.machine then	-- I find it useful to make sure that the component exists.  If something has removed it	-- or the component hasn't loaded it can crash the game when you try to call IsOn().		if inst.components.machine:IsOn() then			-- You would test for player stuff here as well 			return -TUNING.SANITYAURA_SMALL		else        		return 0        	end  -- You need an end to close the if statement. 	end -- closing if inst.components.machineend-- Also make sure in function fn() you put-- inst.components.sanityaura.aurafn = sanityup
If you still have trouble afterwards, post the end of your log.txt after a crash. Edited by zeidrich
  • Developer

@Ipsquiggle

(sorry for combining two things into a single post)

The main thing that I'm curious about, and once again this is not from code diving but from things I've read on the wiki, is "flowers only spawn in the grass biome." Which seems to be true. Flowers will spawn in the large grassland boundary areas. I've seen this because my first year in the game (~36-40 days) usually has me picking gobs of flowers and making lots of garlands to restore my sanity. The game generates with flowers almost everywhere, but they only regenerate in the grassland areas. When I go back to the same area, after the flowers have spawned, if I don't pick the flowers, they are in the same spot.

Yes, right now the flowers aren't "living". Spawn is probably the wrong word to use, as they don't actually "do" any spawning. Rather, during world gen time, all the objects are placed in the world according to the rules in levels.lua, tasks.lua, special_rooms.lua and terrain.lua. Once the generation is complete, all that data is discarded and there are simply objects in the world. They don't really know anything about where they are or why they are there. For most objects (such as flowers) no more are added as the game progresses.

Of course, that's the only example I have. What I'd like to do is sort of the reverse of what zeidrich is proposing. I like terraforming, but I'd like a player to wear out the land they overuse over a long period of time. Too many fires, the land turns to savannah, and potentially rockland. Too much bloodshed in a particular area, ghosts begin to appear.

These are just ideas right now, and I'm not even close to implementing them, but I would bet zeidrich and I are not the only wants who might want to be able to effect a more dynamic world, and have certain things happen magically off camera as they do on camera.

The main challenge with a large simulation approach like this is simply the processing requirements. The reason things don't process offscreen, and why there aren't a lot of dynamic world-shifty-growing-evolving kinds of behaviors, is because we have 10's of thousands of objects in a level and it would murder any computer to have them all processing all the time. That said, there are clever tricks you can do to get this kind of idea across, by using schedules and events.

Two examples that come to mind: One if you wanted flowers to reproduce slowly, you can add a DoTaskInTime with a large delay (look at the growable component for an example of this, it's how spider dens and evergreens work). Two, have changes happen slowly every time an event happens. For example, add a "cursetheground" component the player, and it listens for the "picksomething" event, and has a small chance to turn ground tiles each time a flower is picked. Both these methods avoid doing much or any processing offscreen.

Beyond that it's certainly possible, it's mostly a question of scale... :)

  • Developer

It still crashes, it seems i probably wrote something wrong that is making the game crash, especifically i seems to be ''inst.components.machine:IsOn()'', i'm doing something wrong there, i'm sure. I wish it showed a error message or something, to see what is wrong there.

Also, making a mod instead of simply staring at the code has made me learn a lot on how to the game works, it's amazing.

I'm making some changes which should produce more useful error messages when prefabs aren't working, those will be in the next release.

To your problem: [MENTION=38597]zeidrich[/MENTION] has the right direction, using sanityaura.aurafn.

Just remember that this expects the function to return the appropriate value, not set it:

if [COLOR=#333333]inst.components.machine:IsOn() then    return [/COLOR][COLOR=#333333]TUNING.SANITYAURA_SMALLelse    return 0end
To explain.

When you set the sanityaura.aurafn as zeidrich describes, you're actually saying to the sanityauracomponent, "Rather than using a fixed value for the aura strength, instead call this function, and it will return to you what the value should be."

Thanks to both of you! I'll see if this works right now.The playerprox thing is something i had forgotten to erase for when i started cleaning stuff up from the maxwellphonograph prefab, i didn't really want anything doing with the player being close to the phonograph.Alright, i understood everything, god now i feel so dumb.Hm, now, about my other questions about the names of the other music tracks, what should i do there, really? The names i've used from other directories don't seem to be working. (I'm pretty sure dontstarve/music/music_work should work.)EDIT: Also i just realized that i wrote a negative small sanity aura, heh, i meant a huge, positive sanity aura.

Edited by Irontaco

Ok, next thing my small brain can't figure out. I'm trying to come up with an if statement based on hover text (in cane.lua).Simplistically, like this:

	if HoverText = "Examine Evergreen" then		print "You've hovered over an Evergreen!"	elseif HoverText = "Examine Boulder" then		print "You've hovered over a Rock!"	end
Of course this doesn't work... Any ideas?

	if HoverText = "Examine Evergreen" then		print "You've hovered over an Evergreen!"	elseif HoverText = "Examine Boulder" then		print "You've hovered over a Rock!"	end
Of course this doesn't work... Any ideas?
Maybe you could try...
	if HoverText [COLOR="#FF0000"]==[/COLOR] "Examine Evergreen" then		print "You've hovered over an Evergreen!"	elseif HoverText [COLOR="#FF0000"]==[/COLOR] "Examine Boulder" then		print "You've hovered over a Rock!"	end
:x Edited by milson

Maybe you could try...

	if HoverText [COLOR="#FF0000"]==[/COLOR] "Examine Evergreen" then		print "You've hovered over an Evergreen!"	elseif HoverText [COLOR="#FF0000"]==[/COLOR] "Examine Boulder" then		print "You've hovered over a Rock!"	end
:x
Well, at least that doesn't crash the game, but I'm getting no readout, so it's getting ignored...

Well, HoverText is a Widget, so you will never have it equal a string.What you want is something like:

lmb = GetPlayer().components.playeractionpicker:GetLeftMouseAction()if lmb then 	local actionstring = lmb:GetActionString() 	if lmb.target and lmb.invobject == nil and lmb.target ~= lmb.doer then		local name = lmb.target.name or (lmb.target.components.named and lb.target.components.named.name)	endlocal fulltext = actionstring .. " " .. nameend
There's also adjectives and stackable variables that I'm not going to bother with but they're in hoverer.lua.A question I guess is why do you want to do a string comparison on the hovertext? Wouldn't it be easier to do something like:
if TheInput:GetWorldEntityUnderMouse().name == "Boulder" then print "You're hovering over a Boulder"end-- or probably betterif TheInput:GetWorldEntityUnderMouse().name == STRINGS.NAMES.ROCK_FLINTLESS then print "You're hovering over a Boulder"end
HoverText is a widget that's only really built to display these components, not give access to them. I think it's easier if you are working with the actual Entity rather than some general string representation based on the hover text. For instance, it would break if you wanted to detect if the player was hovering over a pig, because the hover text says the pig's name instead. And sometimes you might have something that changes the verb you use, so it might say "Mine Boulder" instead.

Alright, i've been doing better now! Managed to code something that makes Maxwell lose sanity instead by doing:

local function sanityup(inst, observer)	SaveGameIndex:GetSlotCharacter()	if	inst.components.machine:IsOn() and SaveGameIndex:GetSlotCharacter() == ("waxwell") then	return TUNING.SANITYAURA_LARGE *-4	else	return TUNING.SANITYAURA_LARGE	endend
It's no big thing but after taking 10 minutes about how to do it i feel strangely proud of it.Now, i was thinking about making it degradable, since making it have a durability like the lantern would be way too complicated for my skill level, i thought, why not making it rot? (I know it's a terrible idea.) so yeah, i did this to the code:
require "prefabutil"local assets ={	Asset("ANIM", "data/anim/phonograph.zip"),	Asset("SOUND", "data/sound/maxwell.fsb"),	Asset("SOUND", "data/sound/music.fsb")}local function onhammered(inst, worker)	if inst.components.lootdropper and inst:HasTag("phonograph1") then		inst.components.lootdropper:DropLoot()	end	SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())	inst.SoundEmitter:PlaySound("dontstarve/common/destroy_wood")	inst:Remove()endlocal function onhit(inst, worker)inst.AnimState:PlayAnimation("idle")    inst.SoundEmitter:KillSound("ragtime")    inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_end")endlocal function sanityup(inst, observer)	SaveGameIndex:GetSlotCharacter()	if	inst.components.machine:IsOn() and SaveGameIndex:GetSlotCharacter() == ("waxwell") then	return TUNING.SANITYAURA_LARGE *-4	else	return TUNING.SANITYAURA_LARGE	endendlocal function play(inst)	inst.AnimState:PlayAnimation("play_loop", true)   	inst.SoundEmitter:PlaySound(inst.songToPlay, "ragtime")      	inst:PushEvent("turnedon")endlocal function stop(inst)	inst.AnimState:PlayAnimation("idle")    inst.SoundEmitter:KillSound("ragtime")    inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_end")    inst:PushEvent("turnedoff")endlocal function fn()		local inst = CreateEntity()		local trans = inst.entity:AddTransform()		local anim = inst.entity:AddAnimState()		local sound = inst.entity:AddSoundEmitter()	    MakeObstaclePhysics(inst, 0.7)		anim:SetBank("phonograph")		anim:SetBuild("phonograph")		anim:PlayAnimation("idle")		inst.songToPlay = "dontstarve/maxwell/ragtime"		inst:AddTag("phonograph1")		inst:AddComponent("inspectable")		inst:AddComponent("lootdropper")		inst:AddComponent("sanityaura")		inst:AddComponent("workable")		inst:AddComponent("perishable")		inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERFAST *50) --x50 for testing purposes!		inst.components.perishable:StartPerishing()		inst.components.perishable.onperishreplacement = "purplegem"		inst.components.perishable.perishfn = fn		inst.components.sanityaura.aurafn = sanityup		inst.components.workable:SetWorkAction(ACTIONS.HAMMER)		inst.components.workable:SetWorkLeft(3)		inst.components.workable:SetOnFinishCallback(onhammered)		inst.components.workable:SetOnWorkCallback(onhit)		inst:AddComponent("machine")		inst.components.machine.turnonfn = play		inst.components.machine.turnofffn = stop	    inst.entity:SetSleepRadius(1000)	return instendreturn Prefab( "common/objects/phonograph1", fn, assets),	   --MakePlacer("common/leifstatue_placer", "leifstatue", "leifstatue", "idle" )	   MakePlacer("common/phonograph1_placer", "winter_meter", "winter_meter", "idle" )
Of course, this didn't work at all, but, there was no crash at all, just, the phonograph didn't rot at all. I KNOW it's because it's a structure, and that maybe i could do stuff around to make it work, but i do need some tips here. Also, zeidrich, do you have a Steam/Skype/anywhere i could contact you with?EDIT: Also yeah i just realized i forgot to make the sanity script RETURN the value, not set the value, fixing. Edited by Irontaco

Alright, i've been doing better now! Managed to code something that makes Maxwell lose sanity instead by doing:

It's no big thing but after taking 10 minutes about how to do it i feel strangely proud of it.Now, i was thinking about making it degradable, since making it have a durability like the lantern would be way too complicated for my skill level, i thought, why not making it rot? (I know it's a terrible idea.) so yeah, i did this to the code:Of course, this didn't work at all, but, there was no crash at all, just, the phonograph didn't rot at all. I KNOW it's because it's a structure, and that maybe i could do stuff around to make it work, but i do need some tips here. Also, zeidrich, do you have a Steam/Skype/anywhere i could contact you with?EDIT: Also yeah i just realized i forgot to make the sanity script RETURN the value, not set the value, fixing.
local function sanityup(inst, observer)	SaveGameIndex:GetSlotCharacter()	if	inst.components.machine:IsOn() and SaveGameIndex:GetSlotCharacter() == ("waxwell") then	return TUNING.SANITYAURA_LARGE *-4	else	return TUNING.SANITYAURA_LARGE	endend
require "prefabutil"local assets ={	Asset("ANIM", "data/anim/phonograph.zip"),	Asset("SOUND", "data/sound/maxwell.fsb"),	Asset("SOUND", "data/sound/music.fsb")}local function onhammered(inst, worker)	if inst.components.lootdropper and inst:HasTag("phonograph1") then		inst.components.lootdropper:DropLoot()	end	SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())	inst.SoundEmitter:PlaySound("dontstarve/common/destroy_wood")	inst:Remove()endlocal function onhit(inst, worker)inst.AnimState:PlayAnimation("idle")    inst.SoundEmitter:KillSound("ragtime")    inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_end")endlocal function sanityup(inst, observer)	SaveGameIndex:GetSlotCharacter()	if	inst.components.machine:IsOn() and SaveGameIndex:GetSlotCharacter() == ("waxwell") then	return TUNING.SANITYAURA_LARGE *-4	else	return TUNING.SANITYAURA_LARGE	endendlocal function play(inst)	inst.AnimState:PlayAnimation("play_loop", true)   	inst.SoundEmitter:PlaySound(inst.songToPlay, "ragtime")      	inst:PushEvent("turnedon")endlocal function stop(inst)	inst.AnimState:PlayAnimation("idle")    inst.SoundEmitter:KillSound("ragtime")    inst.SoundEmitter:PlaySound("dontstarve/music/gramaphone_end")    inst:PushEvent("turnedoff")endlocal function fn()		local inst = CreateEntity()		local trans = inst.entity:AddTransform()		local anim = inst.entity:AddAnimState()		local sound = inst.entity:AddSoundEmitter()	    MakeObstaclePhysics(inst, 0.7)		anim:SetBank("phonograph")		anim:SetBuild("phonograph")		anim:PlayAnimation("idle")		inst.songToPlay = "dontstarve/maxwell/ragtime"		inst:AddTag("phonograph1")		inst:AddComponent("inspectable")		inst:AddComponent("lootdropper")		inst:AddComponent("sanityaura")		inst:AddComponent("workable")		inst:AddComponent("perishable")		inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERFAST *50) --x50 for testing purposes!		inst.components.perishable:StartPerishing()		inst.components.perishable.onperishreplacement = "purplegem"		inst.components.perishable.perishfn = fn		inst.components.sanityaura.aurafn = sanityup		inst.components.workable:SetWorkAction(ACTIONS.HAMMER)		inst.components.workable:SetWorkLeft(3)		inst.components.workable:SetOnFinishCallback(onhammered)		inst.components.workable:SetOnWorkCallback(onhit)		inst:AddComponent("machine")		inst.components.machine.turnonfn = play		inst.components.machine.turnofffn = stop	    inst.entity:SetSleepRadius(1000)	return instendreturn Prefab( "common/objects/phonograph1", fn, assets),	   --MakePlacer("common/leifstatue_placer", "leifstatue", "leifstatue", "idle" )	   MakePlacer("common/phonograph1_placer", "winter_meter", "winter_meter", "idle" )

you are making the perish time longerchange
inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERFAST * 50) -- 150 days!
to
inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERFAST  / 50)

you are making the perish time longerchange

inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERFAST * 50) -- 150 days!
to
inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERFAST  / 50)
Oh bloody hell i put the wrong symbol. Thanks for reminding me.EDIT: Nothing really happens, bleh, i may just make it infinite and really expensive. Edited by Irontaco

Well, HoverText is a Widget, so you will never have it equal a string.What you want is something like:

lmb = GetPlayer().components.playeractionpicker:GetLeftMouseAction()if lmb then 	local actionstring = lmb:GetActionString() 	if lmb.target and lmb.invobject == nil and lmb.target ~= lmb.doer then		local name = lmb.target.name or (lmb.target.components.named and lb.target.components.named.name)	endlocal fulltext = actionstring .. " " .. nameend
There's also adjectives and stackable variables that I'm not going to bother with but they're in hoverer.lua.A question I guess is why do you want to do a string comparison on the hovertext? Wouldn't it be easier to do something like:
if TheInput:GetWorldEntityUnderMouse().name == "Boulder" then print "You're hovering over a Boulder"end-- or probably betterif TheInput:GetWorldEntityUnderMouse().name == STRINGS.NAMES.ROCK_FLINTLESS then print "You're hovering over a Boulder"end
HoverText is a widget that's only really built to display these components, not give access to them. I think it's easier if you are working with the actual Entity rather than some general string representation based on the hover text. For instance, it would break if you wanted to detect if the player was hovering over a pig, because the hover text says the pig's name instead. And sometimes you might have something that changes the verb you use, so it might say "Mine Boulder" instead.
[MENTION=38597]zeidrich[/MENTION], this approach is much, much better!I get error "attempt to index a nil value" when it gets to TheInput line though.

Environment probably. Try GLOBAL.Input or GLOBAL.TheInput, I think one of those should work. I do a lot of my mucking about in the console which behaves a bit differently than mods, but should work the same in principle.

Appreciate your pointers and sorry to be such a pain in the ass (I've been working on this off and on for weeks).

GLOBAL.TheInput gets 'variable 'GLOBAL' is not declared

GLOBAL.Input gets 'variable 'GLOBAL' is not declared

Here's where it's at in the cane.lua file:

local function fn(Sim)	local inst = CreateEntity()	local trans = inst.entity:AddTransform()	local anim = inst.entity:AddAnimState()    inst.entity:AddSoundEmitter()            MakeInventoryPhysics(inst)        anim:SetBank("cane")    anim:SetBuild("cane")    anim:PlayAnimation("idle")if GLOBAL.TheInput:GetWorldEntityUnderMouse().name == STRINGS.NAMES.EVERGREEN then print "You're hovering over EVERGREEN"end      inst:AddComponent("weapon")    inst.components.weapon:SetDamage(TUNING.CANE_DAMAGE)    inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")        inst:AddComponent("equippable")      inst.components.equippable:SetOnEquip( onequip )    inst.components.equippable:SetOnUnequip( onunequip )    inst.components.equippable.walkspeedmult = TUNING.CANE_SPEED_MULT        return instend
I'm so close I can taste it!

[MENTION=8728]Irontaco[/MENTION]Consider what this does:

inst.components.perishable.perishfn = fn
You're setting the perish function to fn, which is the initializer for the whole phonograph prefab. It's probably a good thing that it doesn't perish because I expect that would do bad or at least very odd things. You don't even have to set the perishfn. I'd leave that null in your case.I just did the following with the console:Hovered over a boulder and did a = TheInput:GetWorldEntityUnderMouse()a:AddComponent("perishable")a.components.perishable.onperishreplacement = "purplegem"a.components.perishable:SetPerishTime(30) -- 30 secondsa.components.perishable:StartPerishing()And 30 seconds later the boulder turned to a gem. I did it to one of my pet dogs too. Consider that you're basically doing the same thing, except for instead of picking a with the mouse like I did, you get inst passed when the prefab is created.

[MENTION=10028]tehMugwump[/MENTION] Oh, I was wrong. In a prefab, you can access TheInput, you don't need to use GLOBAL. If it were in modmain.lua I think you would have to. You just use TheInput:GetWorldEntityUnderMouse() in a prefab.However, your function runs when the prefab gets generated. This means it's getting the entity under your mouse at the point that prefab gets generated. If that's when a game starts or when the game loads that's a problem, because you're probably not hovering over anything. In general it's a problem, because if this ever gets generated when you're not hovering your mouse over something then TheInput:GetWorldEntityUnderMouse() == nil and when you try and read name from nil you get the "attempt to index a nil value" crash.You could test for nil first, but I think you're checking the player's cursor in the wrong spot anyways. Explain what you're trying to do with the cane.

  • Like 1

Oh, right.Alright i did that and stuff works, i tested by doing 20 seconds and it does work. Now, the usual game day lasts 480 seconds, if i put the time to perish to 480 *20 it should be 20 days, right?Everything is pretty good now, now i'm just going to start making the other phonographs IF i can manage to get the right directory for the music...Thanks a lot, zeidrich, it really helped me learn stuff.

[MENTION=10028]tehMugwump[/MENTION] Oh, I was wrong. In a prefab, you can access TheInput, you don't need to use GLOBAL. If it were in modmain.lua I think you would have to. You just use TheInput:GetWorldEntityUnderMouse() in a prefab.However, your function runs when the prefab gets generated. This means it's getting the entity under your mouse at the point that prefab gets generated. If that's when a game starts or when the game loads that's a problem, because you're probably not hovering over anything. In general it's a problem, because if this ever gets generated when you're not hovering your mouse over something then TheInput:GetWorldEntityUnderMouse() == nil and when you try and read name from nil you get the "attempt to index a nil value" crash.You could test for nil first, but I think you're checking the player's cursor in the wrong spot anyways. Explain what you're trying to do with the cane.

Thanks [MENTION=38597]zeidrich[/MENTION]. I'm giving the cane a couple different uses depending on what your mouse is over at the moment (trees, rocks for example). If I can give TheInput:GetWorldEntityUnderMouse() a dummy value until then, that would be perfect.I try something like local TheInput:GetWorldEntityUnderMouse() == FLOWER and game crashes of course...

Yeah, you can't just put GetWorldEntityUnderMouse into the prefab's initialization function. That only runs once when the prefab is created. It's crashing because most of the time you are getting nil, since nothing is under your mouse. Also, the keyword local in that example has no business being there. local defines a variable's scope, but you're not defining a variable, you're doing a comparison. Essentially that line is saying "local false" because TheInput:GetWorldEntityUnderMouse() is going to return an Entity, and FLOWER is probably undeclared. You'll probabaly get a crash saying that you're trying to operate on FLOWER which is undeclaredTo stop it from crashing you could do something like:entity = TheInput:GetWorldEntityUnderMouse()if entity.name and entity.name == STRINGS.NAMES.FLOWER then--do somethingendHowever, again, it will only do that check a single time, when the prefab is initialized.What you want to look at, if you want the cane to do things when you click on them is to create a component that handles those actions and add that component to the prefab. Look at how CollectUseActions, CollectEquippedActions, CollectInventoryActions, CollectSceneActions etc. get used by existing prefabs.The way I would do it would be:In the prefab, I'd add a component called "caner"In the caner component I would test the target, depending on the target I would assign a different action. Any action that's not defined I'd try to define in ACTIONS from modmain.luaI haven't done this so I couldn't give you step by step instructions.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...