Gamer4Life Posted April 2, 2016 Posted April 2, 2016 I was trying to get a health pack pick up script working from a leadwerks tutorial video and for some reason I'm getting a script nil value on line 11 at ,( if player.script.health < player.script.maxHealth then. ) Anyone know why? Script.health = 25.0 --float "Health" Script.useOnce = true --bool "Use once" function Script:Start() if self.health < 0 then error ("Health can't be a negative value.") end end function Script:Use(player) if player.script.health < player.script.maxHealth then player.script:ReceiveHealth(self.health) if self.useOnce then self.entity:Release() end end end Quote
Rick Posted April 2, 2016 Posted April 2, 2016 The player parameter must be nil which means whatever called this Use function didn't pass a valid object into it. Quote
Thirsty Panther Posted April 2, 2016 Posted April 2, 2016 Try if player.entity.script.health < player.entity.script.maxHealth then 1 Quote
Rick Posted April 2, 2016 Posted April 2, 2016 If the script is what's passed in then just do: if player.health M okater,maxHealth then No need to go back to the entity and then back to the script again. Quote
Gamer4Life Posted April 3, 2016 Author Posted April 3, 2016 Thanks Rick. That was the issue. It took me a while to figure out the line underneath it after I changed the line to what you recommended but essentially since it would not let me use the script I had to identify each by name. If anyone needs a health pack code that seemed to work for me. Script.health = 25.0 --float "Health" Script.useOnce = true --bool "Use once" function Script:Start() if self.health < 0 then error ("Health can't be a negative value.") end end function Script:Use(player) if player.health < player.maxHealth then player.health = self.health + player.health if self.useOnce then self.entity:Release() end end end Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.