Community Forum

Get status of a variable from another script

Forum Overview >> Scripting

CategoryScripting
Created08.06.2016 21:35


Paul Schu (Unknown) 08.06.2016 21:55
Hello,

i need the state of the pipeIsUnloading variable from the Overloading script. i have made the end of the overloading pipe moveable. now you can change the angle with the mouse. To synchronize the movement of the end with the partical animation. i use a script. it should only run if the overloating process is running.
i tried this method but i get this error: "attempt to index local"

function PA:update(dt)
if vehicle.pipeIsUnloading then
dx,dy,dz=getRotation(self.ref);

x,y,z=localDirectionToWorld(self.Discharge, 0,1,0)
alpha = math.acos(x);
alpha=-alpha+math.pi/2


alpha=alpha-dz
setRotation(self.unloading,0,0,alpha);



end;

end;

i hope you can help me

Emil Drefers (Unknown) 09.06.2016 07:20
Hi,

you should be able to access the variable "pipeIsUnloading" with no problem at all.

But your code looks a bit unpretty, but that might be due to the fact that you did not paste everything in here.

You should not use global variables ... please use local variables.
e.g.
local dx,dy,dz=getRotation(self.ref);

You should stick to the naming convention and give variables a name starting with lower case.
e.g.
self.discharge = ....

Concerning your error message it would be nice to know in which line the problem occurs.
You can always insert some print() do see what value a variable has. This might help during debuging.

Cheers,
Emil


Paul Schu (Unknown) 09.06.2016 18:49
Hello,

thx for help.
I forgot to write that the script is not included in the vehicleTypes of the overloadingtrailer.The baffle has its own i3d and xml file. They only share the modDesc.

E:/mods//hawe/HP_PA.lua:23: attempt to index global 'vehicle' (a nil value)
line 23: if vehicle.pipeIsUnloading then

This is the hole script:
PA = {};

function PA.prerequisitesPresent(specializations)
return true;
end;

function PA:load(xmlFile)
self.fillVolumeDischargeInfo = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.fillVolumeDischargeInfo#index"));
self.unloading = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.unloading#index"));
self.extention = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.extention#index"));



end;
function PA:delete()
end;
function PA:mouseEvent(posX, posY, isDown, isUp, button)
end;
function PA:keyEvent(unicode, sym, modifier, isDown)
end;

function PA:update(dt)
if vehicle.pipeIsUnloading then
local dx,dy,dz=getRotation(self.extention);

local x,y,z=localDirectionToWorld(self.fillVolumeDischargeInfo, 0,1,0)
local alpha = math.acos(x);
local alpha=-alpha+math.pi/2


local alpha=alpha-dz
setRotation(self.unloading,0,0,alpha);



end;

end;




Emil Drefers (Unknown) 10.06.2016 07:15
Hi,

somehow the variable "vehicle" must be set/referenced.

Really not sure what your exact plan is.

If PA is a nomral specialization "vehicle" should be replaced with "self".
But that's probably not the case here, right?

Cheers,
Emil





Note: Log in to post. Create a new account here.