sergiohmcl Posted July 8, 2021 Share Posted July 8, 2021 (edited) 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 July 8, 2021 by sergiohmcl Link to comment https://forums.kleientertainment.com/forums/topic/131652-trying-to-move-prefabs-with-inputs/ Share on other sites More sharing options...
zetake Posted July 8, 2021 Share Posted July 8, 2021 (edited) 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 July 8, 2021 by zetake Link to comment https://forums.kleientertainment.com/forums/topic/131652-trying-to-move-prefabs-with-inputs/#findComment-1477298 Share on other sites More sharing options...
sergiohmcl Posted July 9, 2021 Author Share Posted July 9, 2021 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. Link to comment https://forums.kleientertainment.com/forums/topic/131652-trying-to-move-prefabs-with-inputs/#findComment-1477354 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now