Lunarovich Posted March 18, 2015 Share Posted March 18, 2015 Hello, this one is "hurting" me Here is an error message that referes to the System:Print() call: error in function 'Print'.; argument #3 is 'string'; '[no object]' expected. function Script:Collision(entity,position,normal,speed) System:Print(entity:GetKeyValue("name")) if speed>20 and entity:GetKeyValue("name") ~= "Death Trigger" then self:Hurt(100) end end Also, the condition in the third line does not work, although I have an object that is called "Death Trigger" and the script gets activated when I hit it... BTW, don't know what is a third argument of the Print. Also, what does the "'[no object]' expected" means? Quote Link to comment Share on other sites More sharing options...
shadmar Posted March 18, 2015 Share Posted March 18, 2015 Try : System:Print(tostring(entity:GetKeyValue("name"))) Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Lunarovich Posted March 18, 2015 Author Share Posted March 18, 2015 Thanks! When I try it, the System:Print outputs a correct value, ie. Death Trigger, to the console, but the code still doesn't work. Anyway, why do I have to use tostring function. Isn't Entity:GetKeyValue supposed to give me the value that I'm looking for, ie. of type string? EDIT: I've just checked with the type(entity:GetKeyValue("name")) and it does give me a string... This one puzzles me... EDIT: OK, this one, for some reason, works: local name = entity:GetKeyValue("name") System:Print(name) However, this one still does not work if speed>20 and name ~= "Death Trigger" then self:Hurt(100) end even though the name gets the correct value, ie. "Death Trigger" outside the if condition. Inside the if condition, name seems to be an empty string... How strange... At least for me Am I missing something about Lua lexical scoping??? EDIT: It seems that I am trying to call a GetKeyValue on a non-existing entity. Not yet sure, though. Quote Link to comment Share on other sites More sharing options...
shadmar Posted March 18, 2015 Share Posted March 18, 2015 Maybe change ~= to == since ~= means not equal? Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Lunarovich Posted March 18, 2015 Author Share Posted March 18, 2015 Admittedly bad semantics. It's not supposed to be a death trigger. It's a spawn trigger. So, I wouldn't like to get killed when hitting it hard So ~= should stay. Anyway, this is not something that puzzles me. It's a suite of behaviors described in EDITs of post 3. Quote Link to comment Share on other sites More sharing options...
shadmar Posted March 18, 2015 Share Posted March 18, 2015 Do a System:Print (speed) maybe it's below 20? Try a System:Print("hurt") inside your condition incase Hurt() doesn't do what it should. It's hard to tell what it could be without an example map. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Lunarovich Posted March 18, 2015 Author Share Posted March 18, 2015 When the player first hits the "Death trigger" (which is Collision.Trigger), the Entity:GetKeyValue("name") outputs a correct value, ie. "Death Trigger, however, player's speed is 0 for some reason in that and a subsequent tick... Then player gets teleported (via SetPosition) to the respawn point. In the meantime, its speed is about 25 as it should have been when he hits the trigger... Since now the player collides with a normal ground and not a trigger, he dies. Why would the speed be 0 when he hits a trigger? And how comes that an Entity:GetKeyValue("name") is an empty string in all subsequent ticks when a Script:Collision gets called? I mean, aren't we supposed to always collide with an entity and doesn't all entities have names? EDIT: It seems to me that I have a general problem with the Entity:GetKeyValue("name"). I've pinned the problem down to the fact that entity:GetKeyValue("name") sometimes returns an empty string inside the Script:Collision, which I don't understand, as I've explained in the previous paragraph. Quote Link to comment Share on other sites More sharing options...
nick.ace Posted March 18, 2015 Share Posted March 18, 2015 When you are calling entity:GetKeyValue("name") and getting blank strings, it might mean you are colliding with entities with no unique names (possibly CSG or the terrain or water or something). What you may have more luck doing is to flip the situation around. Instead of constant detection on the player, attach this code to the trigger. Right now you are essentially analyzing collisions every loop, and it introduces errors and unexpected behavior with minor collisions, unimportant collisions. If you perform the GetKeyValue check within the trigger code, then you will likely have better results. Also, what is a tick? Do you have the console open while you are running the game? There is always latency with producing output due to the way your operating system works, and there may be some buffering going on to delay it even more. It's very likely that the data is a little old, since it should be a constant flow of data. But, as Shadmar said, it would be helpful if you could provide a map with code (even if it's just a small map just for this purpose). Quote Link to comment Share on other sites More sharing options...
Lunarovich Posted March 19, 2015 Author Share Posted March 19, 2015 Thank you for the answer. However, the fact that I can get more or less better results does not confort me. I expect it to be either a collision with a named entity or no collision at all. I know that I can check if entity ~= nil, but is there a more elegant way that always gives me intended results? Quote Link to comment Share on other sites More sharing options...
macklebee Posted March 19, 2015 Share Posted March 19, 2015 I expect it to be either a collision with a named entity or no collision at all. Except thats not how it works. Just the simple character controller's collision type will cause a collision response with any scene collision type (like terrain), just like nick is referring to. There will be items in the scene that will not have a name key that will cause a collision response based on the collision type assigned. The only suggestion would be to first perform a check to see if the entity has a name then perform the rest of your code. 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Lunarovich Posted March 20, 2015 Author Share Posted March 20, 2015 Thanks macklebee. And thanx everyone for all the explanations. Seems quite clearer now Quote Link to comment Share on other sites More sharing options...
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.