Aphid98 Posted April 8, 2015 Author Share Posted April 8, 2015 @Aphid98 Something is wrong with the key binding. Provide that code please.here it is: cole.lua Link to comment Share on other sites More sharing options...
Blueberrys Posted April 8, 2015 Share Posted April 8, 2015 @Aphid98 Err. You can't just pass the component into AddKeyDownHandler.. you need a key and a function. Also, the AddComponent function doesn't return anything, so "breath" is nil. Try something like this.local function breathe_fire() -- Call a function within your component here (you need to create it first) -- inst.components.firebreath:BreatheFire()end-- Binds the key with the function aboveTheInput:AddKeyDownHandler(key, breathe_fire)- Your firebreath component right now seems like it would fit well on an item, but not a character. You have a function to collect equipped actions, which makes no sense on characters.I suggest changing it up so it has a function which can be called from the key binding.function firebreath:BreatheFire() -- Here, you can shoot a fireball at the direction the character is facing -- Or find the entity below the cursor, and shoot at it -- Or whatever you want the "fire breath" to doend Link to comment Share on other sites More sharing options...
Aphid98 Posted April 8, 2015 Author Share Posted April 8, 2015 @BlueberrysHow would i make it fire at whatever the mouse is over? Link to comment Share on other sites More sharing options...
Blueberrys Posted April 8, 2015 Share Posted April 8, 2015 @Aphid98 You can get the entity under the mouse using:local target = TheInput:GetWorldEntityUnderMouse()And pass that variable to the projectile component's Throw function:-- Where "self.inst" refers to the player instance.-- Syntax is Projectile:Throw(owner, target, attacker)proj.components.projectile:Throw(self.inst, target, self.inst) Edit: Make sure target isn't nil before you pass it. You might also want to make sure it's an enemy, so you don't go around accidentally shooting rocks and trees (unless you want that, which could make it interesting). Link to comment Share on other sites More sharing options...
Aphid98 Posted April 8, 2015 Author Share Posted April 8, 2015 @Aphid98 You can get the entity under the mouse using:local target = TheInput:GetWorldEntityUnderMouse()And pass that variable to the projectile component's Throw function:-- Where "self.inst" refers to the player instance.-- Syntax is Projectile:Throw(owner, target, attacker)proj.components.projectile:Throw(self.inst, target, self.inst) Edit: Make sure target isn't nil before you pass it. You might also want to make sure it's an enemy, so you don't go around accidentally shooting rocks and trees (unless you want that, which could make it interesting). like this?firebreath.lua Link to comment Share on other sites More sharing options...
Blueberrys Posted April 8, 2015 Share Posted April 8, 2015 @Aphid98 Sure, I guess that might work. But you might wanna clean up that code a little. There's a lot of unnecessary and confusing bits in there. Specifically:What does the BreatheFire function do?Why is LaunchProjectile taking in 2 parameters and completely replacing one of them? ("target")CollectEquippedActions is not needed, you can't equip your own firebreath.What is OnAttack doing? When will it be called? Link to comment Share on other sites More sharing options...
Aphid98 Posted April 8, 2015 Author Share Posted April 8, 2015 @BlueberrysI have removed CollectEquippedActions,taken out "target" from the function call,and removed the OnAttack function.The idea behind BreatheFire is that it will light things on fire, but i guess that i dont need it because the projectile launch already does that? Link to comment Share on other sites More sharing options...
Blueberrys Posted April 8, 2015 Share Posted April 8, 2015 @Aphid98 Okay. Make sure you're calling the right function in your key binding, then see if it works. Link to comment Share on other sites More sharing options...
Aphid98 Posted April 9, 2015 Author Share Posted April 9, 2015 @Aphid98 Okay. Make sure you're calling the right function in your key binding, then see if it works.it still doesn't work...log.txtit still doesn't work... log.txt Link to comment Share on other sites More sharing options...
Blueberrys Posted April 9, 2015 Share Posted April 9, 2015 @Aphid98 Problem with the key binding again....steamapps/common/dont_starve/data/scripts/events.lua:21: table index is nilWhat did you pass to the function? Link to comment Share on other sites More sharing options...
TheOoKiller Posted April 9, 2015 Share Posted April 9, 2015 @BlueberrysThanks for the help, now I found new help but still I promise to credit you and also Mobbstar if this mod gets onto Steam Workshop! Link to comment Share on other sites More sharing options...
Aphid98 Posted April 9, 2015 Author Share Posted April 9, 2015 @BlueberrysI wrote: local prefabs = {} local fn = function(inst) -- choose which sounds this character will playinst.soundsname = "maxwell" -- a minimap icon must be specifiedinst.MiniMapEntity:SetIcon( "wolfgang.png" ) -- todo: Add an example special power here.local function breath_fire() inst.components.firebreath:LaunchProjectile()endlocal key = GLOBAL.KEY_G -- See constants.lua for all keys/codes TheInput:AddKeyDownHandler(key, breath_fire)end Link to comment Share on other sites More sharing options...
Blueberrys Posted April 9, 2015 Share Posted April 9, 2015 @Aphid98 If this isn't in modmain, remove "GLOBAL". You only need to use the GLOBAL table when accessing global variables from modmain, other scripts already have access to them. Link to comment Share on other sites More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 @Aphid98 If this isn't in modmain, remove "GLOBAL". You only need to use the GLOBAL table when accessing global variables from modmain, other scripts already have access to them.i can actually load the world now! But, there is a new error. here is the log and the code:local fn = function(inst) -- choose which sounds this character will playinst.soundsname = "maxwell" -- a minimap icon must be specifiedinst.MiniMapEntity:SetIcon( "wolfgang.png" ) -- todo: Add an example special power here.local function breath_fire() inst.components.firebreath:LaunchProjectile()endlocal key = KEY_G -- See constants.lua for all keys/codes TheInput:AddKeyDownHandler(key, breath_fire)endlog.txt Link to comment Share on other sites More sharing options...
Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 @Aphid98Your log:...nt_starve/data/../mods/Cole/scripts/prefabs/cole.lua:49: attempt to index field 'firebreath' (a nil value)I think you forgot to add the firebreath component to your character.inst:AddComponent("firebreath") Link to comment Share on other sites More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 @Aphid98Your log:...nt_starve/data/../mods/Cole/scripts/prefabs/cole.lua:49: attempt to index field 'firebreath' (a nil value)I think you forgot to add the firebreath component to your character.inst:AddComponent("firebreath")I've added it and i got a new error:here is the log log.txt Link to comment Share on other sites More sharing options...
Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 @Aphid98 Have a look at this guide, it'll help you figure out what's wrong in most of these cases. Your log:.../data/../mods/Cole/scripts/components/firebreath.lua:21: attempt to index local 'attacker' (a nil value)See line 21 Link to comment Share on other sites More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 BlueberrysI'm not sure whats wrong... here is the code:function firebreath:LaunchProjectile(attacker)local target = TheInput:GetWorldEntityUnderMouse() if self.onprojectilelaunch then self.onprojectilelaunch(self.inst, attacker, target) end local proj = SpawnPrefab(self.projectile)if proj and proj.components.projectile then proj.Transform:SetPosition(attacker.Transform:GetWorldPosition() ) <---------- bad part proj.components.projectile:Throw(self.inst, target, attacker)endend Link to comment Share on other sites More sharing options...
Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 @Aphid98 The error message is telling you that "attacker" is nil (empty). Where is the variable coming from? Find out why it's empty at that point.Hint: Check the parameters Link to comment Share on other sites More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 Blueberrysso, attacker is not defined? maybe if i added "inst:AddComponent("attacker")"? Link to comment Share on other sites More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 no, because there isn't a component named "attacker"... Link to comment Share on other sites More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 @BlueberrysDid it! I needed to type:function firebreath:LaunchProjectile("cole")new error though:.../data/../mods/Cole/scripts/components/firebreath.lua:21: attempt to index field 'Transform' (a nil value) Link to comment Share on other sites More sharing options...
Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 @Aphid98 Those are both incorrect. "attacker" is a parameter for the LaunchProjectile function. You must pass in a value for the parameter, or it will be blank. Check if you're passing in anything when you are calling the function. Info on variables. Link to comment Share on other sites More sharing options...
Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 no, because there isn't a component named "attacker"... That's correct. The reason that it worked for the previous one is because you are trying to access the component "firebreath". Not all variables work that way, only components. ( "inst.components.some_component" ) Link to comment Share on other sites More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 @Blueberrysso what about the new error? 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.