sergiohmcl Posted July 8, 2021 Share Posted July 8, 2021 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. Link to comment Share on other sites More sharing options...
zetake Posted July 8, 2021 Share Posted July 8, 2021 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. Link to comment 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 Share on other sites More sharing options...
Recommended Posts
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.