Jump to content

set/getElementData problem


Recommended Posts

Hello!

I have almost finished a script, but I have some trouble figuring this problem:

What I want to do is to save a certain vehicleComponent's rotation, and call on that rotation/value later on.

But I get the error: Attempt to perform arithmetic on global 'ox' (a nil value)

From what I can see the setElementData doesn't save the original value for some reason.

 

setElementData should save the rotation of "gear_f" here under the name "ox" (original rotation on x-axis)

function shamalDisableGear()
    local vehicle = getPedOccupiedVehicle(localPlayer)
	local ox = getVehicleComponentRotation(vehicle, "gear_f") -- should save it here
	local originalRotation = setElementData(vehicle, "gear_f", ox, true) -- should save it here
    if(vehicle)then
        if getElementModel(vehicle) == 519 then
		toggleControl ("sub_mission", false)
		end
	end	
end
addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), shamalDisableGear )

 

Later on, when the setElementData is called by getElementData:

function shamalGearFront(button, press)
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if(vehicle)then
    if getElementModel(vehicle) == 519 then
	if button == "2" and (press) then
	if gearstate == 0 then
	local rx, ry, rz = getVehicleComponentRotation(vehicle, "gear_f")
setTimer(function ()
            rx = rx - 3
			if rx < 0 then
            rx = 360 - rx
			end
		    setVehicleComponentRotation(vehicle, "gear_f", rx-3, ry, rz)
end,50,33)
		elseif gearstate == 1 then
		if getElementData(vehicle, "gear_f", ox, true) then -- it seems it doesn't save the original value (ox)
		setVehicleComponentRotation(vehicle, "gear_f", ox-90, oy, oz)
setTimer(function ()
            rx = rx +1
		    setVehicleComponentRotation(vehicle, "gear_f", rx+1, ry, rz)
end,50,90)
		end
	end
end
end
end
end
addEventHandler ( "onClientKey", root, shamalGearFront )

 

What is causing this problem?

Thanks in advance for your help,

 

-Noah

Edited by Noah_Antilles
Link to comment
  • Moderators
local ox = getElementData(vehicle, "gear_f") 
-- ox can be used after here
if ox then -- isn't it false or nil?

end

getElementData has a different syntax than setElementData. Check wiki pls.

 

  • Like 2
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...