DerRidda Posted August 29, 2014 Share Posted August 29, 2014 This seems like a bug but I'm not 100% sure. I have an entity set up to change a variable within the player entity on collision, to do that I check for the player KeyValue "type" to be "player" to prevent the script executing on the environment and tossing errors because that value obviously doesn't exist in some random prop or the floor. But that's exactly what happens when I actually walk over the entity. The if statement for the KeyValue gets passed properly, as it should but then I get nil value erros all the time, whether I try it via directly changing the variable I was aiming for, or calling a method I created within the player script just for that. It seems as if entity gets updated while one and the same iteration of the script is still running, making that value unreliable. Or I'm I misunderstanding the parameter entity here and we get more than one entity? (The documentation on that is practically non-existent.) Link to comment Share on other sites More sharing options...
Rick Posted August 29, 2014 Share Posted August 29, 2014 Can you show us the code inside your collision function. Link to comment Share on other sites More sharing options...
DerRidda Posted August 29, 2014 Author Share Posted August 29, 2014 Sure function Script:Collision(entity, position, normal, speed) if self.triggered == false then if entity:GetKeyValue("type") == "player" then entity.weapon.ammo = entity.weapon.ammo + self.capacity self.pickup:Play() self.triggered = true end end end entity.weapon.ammo = entity.weapon.ammo + self.capacity tosses the error, weapon is a nil value, telling me it isn't even using the right value for entity, the one it was just using for that if statement before. Same deal if I replace the line with entity:AddAmmo(self.capacity), which is a function I've written to see if that works. Link to comment Share on other sites More sharing options...
Rick Posted August 29, 2014 Share Posted August 29, 2014 I assume weapon is a variable inside the script attached to the player script? Every entity has a script variable (it's just nil if no script attached). So what you want is: entity.script.weapon.ammo = entity.script.weapon.ammo + self.capacity Link to comment Share on other sites More sharing options...
DerRidda Posted August 29, 2014 Author Share Posted August 29, 2014 Oops, thank you. Major derp out on my part. Link to comment Share on other sites More sharing options...
Recommended Posts