Krelle Posted November 25, 2014 Share Posted November 25, 2014 Firstly I am sorry if this question has been answered over 100 times before. I have searched the forum without finding an usable answer, on how to do this in Lua. I have tried out code, I thought might work or be related without getting the result i wanted. I have a pivot.When the player collides with the pivot, I want to change the texture on a different object lets call it box1 the collision and change of texture is not a problem. The problem is how I change the box's texture from within the script of the pivot below is an example of an failed attempt at calling a function within a diffrent script. This script would be attached to the pivot function Script:Collision(entity, position, normal, speed) if (entity:GetKeyValue("name") == "Player") then // the function test123 is located inside the script attached to box1 CallFunction("test123"); end end Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted November 25, 2014 Share Posted November 25, 2014 You are colliding with the entity that is pressumably the box? If so do the following: entity.script:YourFunction() Quote Link to comment Share on other sites More sharing options...
Krelle Posted November 25, 2014 Author Share Posted November 25, 2014 You are colliding with the entity that is pressumably the box? If so do the following: entity.script:YourFunction() Thank you for replying to my question. I am colliding with a pivot, not the box itself. Please excuse me for my badly formulated post, english is not my first language. I will do my best to try and formulate myself more clearly. Below is a picture of my scene Below is the (not working) code for the pivot right in front of the player function Script:Collision(entity, position, normal, speed) if (entity:GetKeyValue("name") == "Player") then CallFunction("test123"); end end below is the code for box1 Script.Material1 = "" --path function test123() self.entity:SetMaterial(self.Material1) end I want the material on box1 to change when I collide with the pivot. Please note that the code I posted, probably is wrong, and is only here to demonstrate what i wish to achieve Quote Link to comment Share on other sites More sharing options...
shadmar Posted November 25, 2014 Share Posted November 25, 2014 Pivots are not collidable, use an invisible csg box instead. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Krelle Posted November 25, 2014 Author Share Posted November 25, 2014 Pivots are not collidable, use an invisible csg box instead. Thank you for your help. This information was very useful to me, now I am getting error messages. However the original problem persists as I cant use self.entity to change an external object. What do i replace the self.entity with, in order to get the following function to work, when it is called from another script ? Script.Material1 = "" --path function test123() self.entity:SetMaterial(self.Material1) end to be a little more clear "self" must be referring to the object attached to the script or the script itself. But if you don't want to refer to the object itself but a different object, what do you use ? I Imagen it would be something like box2.entity:SetMaterial(box2.Material1) however this is not working Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 25, 2014 Share Posted November 25, 2014 'Script.Material1' is not a material. For 'entity:SetMaterial()' to work, you have to either load a material using 'Material:Load()' or create a material using Material:Create(). 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...
Krelle Posted November 25, 2014 Author Share Posted November 25, 2014 'Script.Material1' is not a material. For 'entity:SetMaterial()' to work, you have to either load a material using 'Material:Load()' or create a material using Material:Create(). Thank you for replying to my problem. I tried out loading the material in the manner you suggested, however it still does not work. Leadwerks produce the following error message when I call the function from another script : attempt to index global 'self' (a nil value) in the function : function test123() mymaterial = Material:Load("/path/to/texture/texturename.mat") self.entity.SetMaterial(mymaterial) end The script works, if I use it within the script attached to the object : function Script:Collision(entity, position, normal, speed) if (entity:GetKeyValue("name") == "Player") then mymaterial = Material:Load("/path/to/texture/texturename.mat") self.entity:SetMaterial(mymaterial) end Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 25, 2014 Share Posted November 25, 2014 Thank you for replying to my problem. I tried out loading the material in the manner you suggested, however it still does not work. Leadwerks produce the following error message when I call the function from another script : in the function : function test123() mymaterial = Material:Load("/path/to/texture/texturename.mat") self.entity.SetMaterial(mymaterial) end Thats because 'self' in that function does not exist. The script works, if I use it within the script attached to the object : function Script:Collision(entity, position, normal, speed) if (entity:GetKeyValue("name") == "Player") then mymaterial = Material:Load("/path/to/texture/texturename.mat") self.entity:SetMaterial(mymaterial) end It works here because 'self' in this function refers to 'Script'. 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...
Krelle Posted November 25, 2014 Author Share Posted November 25, 2014 Thats because 'self' in that function does not exist. This totally makes sense, so what do i replace self with in order for the function to work as intended ? 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.