Jump to content

Recommended Posts

Posted

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

Posted

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

 

scene.png

 

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

Posted
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

Posted

'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().

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted
'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

Posted

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'.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

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 ?

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...