Category | Scripting |
Created | 23.09.2017 03:47 |
Carter Nb (Unknown) | 23.09.2017 03:47 |
---|---|
I am trying to use the function VehicleMotor:getTorque(), but whenever I do it gives me the error: Error: dataS/scripts/vehicles/VehicleMotor.lua(248) : attempt to index field 'torqueCurve' (a nil value) here is my entire script: torque = VehicleMotor:getTorque(40, true) I tried putting a period instead of a colon in between Motor and getTorque, but that gives me errors too I also errors trying to use getLastSpeed( lastSpeed value is nil error) and geLastMotorRpm,(can't quite remember the error here, if the other two are solved I'll post this error too) all of these errors occur within the scripts of giant's software, not in my code please help |
Emil Drefers (Unknown) | 26.09.2017 10:36 |
---|---|
Hi, you can find the source code here: https://gdn.giants-software.com/documentation_scripting.php?version=script&category=69&class=3543 You might also consider how you are calling the function ... VehicleMotor.getTorque(self.vehicleMotor, 40, true) or self.vehicleMotor:getTorque(40, true) To me, it looks like the vehicle motor has not been initialized correctly. Cheers, Emil |
Carter Nb (Unknown) | 27.09.2017 13:46 |
---|---|
now it just says: attempt to index local 'self' (a nil value) in my script, using either self.vehicleMotor:getTorque or VehicleMotor.getTorque(self.vehicleMotor, here is my new code (does not work) function Ekotune:draw(self) torque = VehicleMotor.getTorque(self.vehicleMotor, 40, true); rpm = VehicleMotor.getlastMotorRpm(self.vehicleMotor); hpPower = (torque*1000 * rpm*math.pi/30)/735.49875; -- local hpPower = power/735.49875; print("torque:" .. torque) print("rpm" .. rpm) print("power" .. power) print("hp" .. hpPower) end; ALSO, some functions like VehicleMotor:getTorqueCurve() don't produce any errors, but using a print command, dont print anything |
Emil Drefers (Unknown) | 04.10.2017 07:05 |
---|---|
Hi, well, self.vehicleMotor must have been initialized, otherwise nothing works correctly ;) So, do you initialize this variable? Cheers, Emil |
Carter Nb (Unknown) | 04.10.2017 13:20 |
---|---|
so how would I initialized the variable? something like this? self.vehicleMotor = VehicleMotor |
Emil Drefers (Unknown) | 04.10.2017 15:26 |
---|---|
Hi, well that depends on what the variable has to represent. A variable representing a floating point number would be local variableX = 2.0; But, in the case of the VehicleMotor you are using a seperate object which needs to be instantiated. So, in you need to call a 'constructor'. self.vehicleMotor = VehicleMotor:new(...) Please pay attention to the arguments of the 'constructor'; https://gdn.giants-software.com/documentation_scripting.php?version=script&category=69&class=3543#new48043 Cheers, Emil |
Carter Nb (Unknown) | 05.10.2017 02:38 |
---|---|
I tried but once again I have an error, my code: self.vehicleMotor = VehicleMotor:new(vehicle, 1000, 2200, 30, 15, AnimCurve:new( interpolFunction, interpolDegree ), 1.5, 20, 40, 20, 200, 40, 250, 1, 100, nil, 83, 1) -- error occurs here print(VehicleMotor:getTorqueCurve()) error: Ekotune_mod.lua:43: attempt to index global 'self' (a nil value) |
Emil Drefers (Unknown) | 05.10.2017 06:31 |
---|---|
Hi, well this line of code must be placed inside a 'valid environment'. If you show us your complete script, we might be able to help you. Cheers, Emil |
Carter Nb (Unknown) | 05.10.2017 13:13 |
---|---|
the -- were things I was trying out that didn't work ignore those Ekotune = {} torqueCurve = {} table.insert(torqueCurve, 0.9) table.insert(torqueCurve, 0.97) table.insert(torqueCurve, 1) table.insert(torqueCurve, 1) table.insert(torqueCurve, 0.88) table.insert(torqueCurve, 0.72) --torqueCurve[0.9] = torque --torqueCurve[0.97] = torque --torqueCurve[1] = torque --torqueCurve[1] = torque --torqueCurve[0.88] = torque --torqueCurve[0.72] = torque -- <torque normRpm="0.45" torque="0.9"/> -- <torque normRpm="0.5" torque="0.97"/> -- <torque normRpm="0.59" torque="1"/> -- <torque normRpm="0.72" torque="1"/> -- <torque normRpm="0.86" torque="0.88"/> -- <torque normRpm="1" torque="0.72"/> --addModEventListener(Ekotune); --BaseMission.addVehicle(...) --ShopScreen.onVehicleBought(...) -- VehicleShopBase.new(...) -- VehicleShopBase.delete(...) -- VehicleShopBase.update(...) -- StoreItemsUtil.getDefaultConfigId(...) --StoreItemsUtil[] --ShopScreen.updateShopItemList() --ShopScreen.updateStoreItemData() --g_shopScreen.isSelling -- g_shopScreen.selectionList[] -- g_shopScreen.vehicleItemTemplate[] -- ShopScreen.canBeBought(...) --ShopScreen.class(...) --StoreItemsUtil.storeItems[] local interpolFunction = linearInterpolator1 local interpolDegree = 1 function Ekotune:preLoad(savegame) if savegame ~= nil then end end function Ekotune:load(savegame) --local Ekotune = getXMLFloat(self.xmlFile, "vehicle.Ekotune") if savegame ~= nil then end end function Ekotune:postLoad(savegame) if savegame ~= nil then end end ConfigurationUtil.registerConfigurationType("Ekotune", "Ekotune", Ekotune:preLoad(), Ekotune:load(), Ekotune:postLoad(), ConfigurationUtil.SELECTOR_MULTIOPTION) --Vehicle:addBoughtConfiguration("Ekotune", self.xmlFile) function Ekotune:keyEvent(unicode, sym, modifier, isDown) end; function Ekotune:mouseEvent(posX, posY, isDown, isUp, button) end; function Ekotune:delete() end; function Ekotune:update(dt) --items = StoreItemsUtil.storeItemsByXMLFilename[self.configFileName:lower()] --print(items) --StoreItemsUtil.removeStoreItem("tractors", "zetorMajor") --ShopScreen.updateShopItemList("tractors", false) --configId = self.configurations("Ekotune") --print(configId) --Vehicle:addBoughtConfiguration("Ekotune", self.xmlFile) end print("test" .. 1) function Ekotune:draw(self) end; --torqueCurve = VehicleMotor:getTorqueCurve() -- VehicleMotor:new("caseIH1455", 1, 2200, 40, 16, torqueCurve, 1.5, 20, 40, 20, 250, 40, 250, 1, 10, 1, 83) --print("I worked!") -- ShopScreen.PAGE_CATEGORY -- ShopScreen.onCreateCategoryIcon(...) -- ShopScreen.onCreateCategoryName(...) self.vehicleMotor = VehicleMotor:new(vehicle, 1000, 2200, 30, 15, AnimCurve:new( interpolFunction, interpolDegree ), 1.5, 20, 40, 20, 200, 40, 250, 1, 100, nil, 83, 1) print(VehicleMotor:getTorqueCurve()) |
Emil Drefers (Unknown) | 09.10.2017 09:18 |
---|---|
Hi, please check out the Motorized Specialization: https://gdn.giants-software.com/documentation_scripting.php?version=script&category=70&class=3493 (starting ~line 353) It loads/creates a valid VehicleMotor. One thing I noted which is very likely not correct in your example is the 'torqueCurve'. Cheers, Emil |
Carter Nb (Unknown) | 09.10.2017 16:01 |
---|---|
this is the new code, which works now local torqueCurve = AnimCurve:new(linearInterpolator1); newMotor = VehicleMotor:new(self, 1000, 2200, 30, 14, torqueCurve, 1.5, 20, 40, 20, 200, 40, 250, 1, 100, 0, 83, 1) print(newMotor:getMinRpm()) -- prints 1000 how can I add this motor to a config or vehicle? can it be added to a config like the one below? ConfigurationUtil.registerConfigurationType("Ekotune", "Ekotune", Ekotune:preLoad(), Ekotune:load(), Ekotune:postLoad(), ConfigurationUtil.SELECTOR_MULTIOPTION) |
Note: Log in to post. Create a new account here.