Sign in to follow this  
sergiohmcl

Trying to move prefabs with inputs

Recommended Posts

sergiohmcl    0

I started with modding recently and I've been reading some stuff in the forum in order to understand how all the things work. I tried, then, create my own mod, which consists (in theory) of moving maxwell's shadows in the direction of the mouse by pressing some key.

I found some things in the forum and tried to get all the info together and I did the following.

 

function Func()
    
	GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_V, function()
		pt = TheSim:GetPosition()
		if GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_V) then
			self.inst.components.locomotor:RunInDirection(self.inst:GetAngleToPoint(pt))
			self.inst.components.locomotor:RunForward()
		end
	end)
end

AddPrefabPostInit("shadowlumber", Func)

That was my base. I got an error saying "attempt to index global variable 'TheInput' (nil value)" or something along these lines. Then I tried to remove that part of the code, it is, deleting all the stuff with IF THEN and the part with 'IsKeyDown'.

Then I got a new error saying "attempt to index global variable 'self' (nil value)".

I took out all the 'self's in the code and got the same error. I also tried making self as an argument of the function.

Finally, I tried to adress the object "shadowlumber" directly (I didn't know if that would work tho), replacing all the "self" by "shadowlumber".

By now I don't know what to do. If someone could point me some direction...

Note: I'm testing all in offline mode.

Edited by sergiohmcl

Share this post


Link to post
Share on other sites
zetake    12
local function Func(inst)
	GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_V, function()
		local pt = GLOBAL.TheInput:GetWorldPosition()
		local angle = inst:GetAngleToPoint(pt)
		inst.components.locomotor:RunInDirection(angle)
	end)
end

AddPrefabPostInit("shadowlumber", Func)

But where do you have prefab shadowlumber?

I can't find it anywhere.

Edited by zetake

Share this post


Link to post
Share on other sites
sergiohmcl    0
3 hours ago, zetake said:

local function Func(inst)
	GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_V, function()
		local pt = GLOBAL.TheInput:GetWorldPosition()
		local angle = inst:GetAngleToPoint(pt)
		inst.components.locomotor:RunInDirection(angle)
	end)
end

AddPrefabPostInit("shadowlumber", Func)

But where do you have prefab shadowlumber?

I can't find it anywhere.

Thank You!!

It worked.

I will try to hand it from here.

Also, I must confess I didn't find "shadowlumber" in prefabs files too and i don't have a clue where they are, but I found in wiki this is the prefab code for maxwell's lumber and when trying c_give( "shadowlumber") in console while in game, it spawned a shadow. It worked tho.

Thank You again.

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this