Jump to content

Nothing here.


 Share

Recommended Posts

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

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

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

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...