Xwad Posted March 13, 2019 Share Posted March 13, 2019 Hmmm i'm wondering why does this not work. line 3: unexpected symbol near ' function rotate() for i,v in ipairs(getElementsByType("vehicle")) do local _,_,rh = getVehicleComponentRotation(v, "misc_a") setVehicleComponentRotation(v, "misc_a", _,_,rh+2) end end addEventHandler("onClientRender", root, rotate) Link to comment
Moderators IIYAMA Posted March 13, 2019 Moderators Share Posted March 13, 2019 (edited) @Xwad You used or copied+past a special/invisible characters on line 3. Fixed: local _, _, rh = getVehicleComponentRotation(v, "misc_a") Which is somehow located in here: local _,_,rh = getVehicleComponentRotation(v, "misc_a") And if we debug that: local theString = " " print(string.byte(theString,1,#theString)) 32 239 187 191 239 187 191 32 239 187 191 239 187 191 32 239 187 191 32 32 32 32 32 32 32 32 32 32 32 32 32 239 187 191 239 187 191 32 32 32 32 Holy ! Edited March 13, 2019 by IIYAMA 1 Link to comment
Xwad Posted March 13, 2019 Author Share Posted March 13, 2019 Well, although this problem is fixed, i got a new one haha line 4: attempt to perform arithmetic on local rh a nil value this means that rh does not have a value? Link to comment
Moderators IIYAMA Posted March 13, 2019 Moderators Share Posted March 13, 2019 @Xwad Yup local rh print(rh * 10) input:4: attempt to perform arithmetic on a nil value (local 'rh') https://en.wikipedia.org/wiki/Arithmetic Link to comment
Xwad Posted March 13, 2019 Author Share Posted March 13, 2019 (edited) yeah but i get the value with getVehicleComponentRotation, so why is it not working? Edited March 13, 2019 by Xwad Link to comment
Moderators IIYAMA Posted March 13, 2019 Moderators Share Posted March 13, 2019 (edited) 7 minutes ago, Xwad said: yeah but i get the value with getVehicleComponentRotation, so why is it not working? It returns nil/false when: Maybe the vehicle doesn't have that component? (for sure) There is no vehicle. (for sure) Or it might not be counted if it has fallen off. (maybe) Or if the vehicle isn't streamed in. (maybe) etc. So take always in account that something can go wrong. Always validate the output. In most cases this is enough: (especially when it is a MTA function) if rh then end Edited March 13, 2019 by IIYAMA Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now