Jump to content

Accessing variable from other script


aiaf
 Share

Recommended Posts

Im not used to this le scripts.So have quick question.

 

In fps player script local camera is created:

self.camera = Camera:Create()

How can i access this camera from another script ? I want to se the position from another script.

Is it any way or i should create a global camera.

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

SetRotation doesnt work on fps player.

I found in forums SetInput , but i cant make it work so far.

I just want to rotate the camera say 90 degree on y axis.Any ideas?

 

Script.mapname=""--string "Map Name"

function Script:Start()
	self.enabled=true
end

function Script:Collision(entity, position, normal, speed)
		--ent = world:FindEntity("simplefpsplayer")
		entity:SetPosition(-9, 0, 0, true)
		
		--What to do here to rotate the simple fps player camera 
end

function Script:Enable()--in
	if self.enabled==false then
		self.enabled=true
		self:CallOutputs("Enable")
	end
end

function Script:Disable()--in
	if self.enabled then
		self.enabled=false
		self:CallOutputs("Disable")
	end
end

 

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

9 hours ago, aiaf said:

Im not used to this le scripts.So have quick question.

 

In fps player script local camera is created:


self.camera = Camera:Create()

How can i access this camera from another script ? I want to se the position from another script.

Is it any way or i should create a global camera.

It is reasonable to pass in a camera as well.  Not sure I would make it global.

If you have something like 

 

Script.camera=nil            --entity    "Camera"

 

then you can set this via dropping a camera from the editor onto this form element in the properties bit and at runtime the editor camera will be set to be the one you dropped on the element.

You could also set a camera programatically created elsewhere onto this same variable.  I think all Script.<PROPERTY> things are accessible everywhere, though only when the object the object exists as an instance you have setup in the editor or programatically created from a prefab or by attaching the script to the model.  This probably sounds complex but it's not that really.

 

 

Link to comment
Share on other sites

9 hours ago, aiaf said:

How can i access this camera from another script ?

You can access a variable in any script usually by getting a reference to the object then it's script then the property or function like this.   

item.script.myproperty = "newvalue"

item.script:MyFunction("newvalue")

So how do you get a reference to the object in the first place you might ask.  Well you CAN scan the list of possible objects in the whole world and try to match something up (like a 'type' or 'name' property you've created in the script), but this is usually a bad idea.  Usually it is best to setup these references in the editor or via interactions with objects via collisions etc.

If you do access an object it is usually best to TEST the presence of the thing you expect to exist otherwise something unexpected might trigger firing instead.  For example in a teleporter you might test if a property on an enemy or player, but what happens if someone drops an prop in the teleporter and that prop does NOT have the property you have on the players and enemies. Script crash is what probably happens. 

Here is how you can test for a function or a bool (there are other types such as number and string i think).

if self.enableInstances and type(item.script["Enable"])=="function" then
	item.script:Enable()
end
if self.enableInstances and type(item.script["timeOwnDeath"])=="boolean" then
	item.script.timeOwnDeath = not self.destroyChildren
end	

 

 

 

Link to comment
Share on other sites

1 hour ago, aiaf said:

I just want to rotate the camera say 90 degree on y axis.Any ideas?

If you want to rotate a camera then you need to consider what is rotating around.  I mean do you want to turn/pan the camera from it's current point, or rotate it from a distance around some other point.  If it's the second one then you would usually use a pivot as a child of the object and have the pivot at the point you want to rotate around.

With the FPS controller I think it can be a bit tricky as I THINK it sets the rotation quite late in the script and probably wipes out what you may have setup earlier.  This is quite common in games....to first gather up a number of criteria on things that might affect movement and then finally apply what the end result is towards the end.

If you are finding cameras and controllers tricky I suggest taking a look at both the spectator cam script (where things are a bit simpler) and create the marble game project and check the camera there, which again is simpler and you can easier test how you think things should work without worrying about things like mouse smoothing and camera smoothing that are probably affecting things in the FPS script.

Need any more help just ask....the standard LW forums also have some answers on these issues I think so may have more info than I am giving here, though it can take time to locate, in which case just pop back.

 

Link to comment
Share on other sites

Thanks i got it.

 

In collision of the fps player i have:

	if ename == "EastGate" or ename == "WestGate" or ename == "NorthGate" or ename == "SouthGate" then
		entity.script.target = entity:GetKeyValue("name")
	end

And in collision of the gate:

if self.target == "EastGate" then 
	entity:SetPosition(-9, 0, 0, true)
	entity.script.camRotation.x = 0
	entity.script.camRotation.y = 90
	entity.script.camRotation.z = 0

 

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...