![]() |
|
Questions and Documentation Requests - Printable Version +- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk) +-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html) +--- Forum: Starfall (https://teamscm.co.uk/forum-7.html) +--- Thread: Questions and Documentation Requests (/thread-903.html) |
Questions and Documentation Requests - Person8880 - 08-05-2015 Got any questions about Starfall? Want a function documented? Post here and I'll try to get around to answering/documenting. RE: Questions and Documentation Requests - Person8880 - 08-05-2015 I'm going to start by pre-emptively explaining input validation in Starfall. There's 3 stages to input validation:
1. Object validation check Objects that exist in the game world, e.g entities, are first checked to make sure that the entity object you're running a function on still exists in the game world. If they do not, then an error of the form "Attempted to use an invalid Entity" is thrown. How to make sure you don't hit this error Check entity objects you pass around to make sure they're valid using the global function IsValid().
2. Function argument type check Once the object is verified as valid (or if it's a library function), the next check is on the type of value being passed through. A function that expects a Vector will throw an error if the argument is not a Vector, and so on. How to make sure you don't hit this error You should already be aware of what types you're passing round. The most common type check failure will be passing nil instead of the expected value. You can avoid this by making sure your input isn't nil, and if it's an entity, then it's also valid.
There shouldn't be any need to verify the type using the type() function, but if you're absolutely unsure of the type going through, you can check it yourself first with:
3. Function argument value check The last stage is only currently applicable to numbers, Vectors and Angles. This check makes sure that the number, or components of the Vector/Angle are not NaN. NaN comes around from division by 0 or other forms of bad input being passed around (such as some vector operations like Vector:GetNormal() and Vector:Normalize(), which divide by the length of the vector). How to make sure you don't hit this error Make sure you're not ever dividing by 0. If you're dealing with forces or other vectors that may become large, make sure you clamp the size of the vector so that it does not end up overly large. To clamp a vector's magnitude:
You can also directly check for NaN values using the standard check:
But in practise you should not have NaN values lying around.
RE: Questions and Documentation Requests - Liizzii - 05-02-2016 Request: Poly's and vertexes. also the vertex documentation need a better explanation of it's arguments than x,y,u,v RE: Questions and Documentation Requests - Person8880 - 05-02-2016 The in-game documentation has been updated with an example on render.drawPoly, and render.vertex has been marked as deprecated as it's just adding confusion. RE: Questions and Documentation Requests - Sir_Cuddles - 19-04-2019 I am wondering how to get quaternions to work in starfall, I was looking at the quaternion library documentation and it seems the "quaternion.New()" function is what I need to use but I can not seem to get it to work. I tried "quaternion.New(Ang)" were Ang is an angle as well as "quaternion.New(E)" were E is an entity and it does not seem to work. I see the function in the documentation says "New(self, ...)" were ... is args but I am not sure what the "self" means and it does not explain. I know I must be doing something wrong. EDIT: Also, I couldn't find any way to do a change in vector or cross/dot products of vectors so I programmed my own functions for them, if there is already functions for them please tell me otherwise it would be nice if they could be added Code: function deltaV( V )
if ( X == nil ) then
V1 = V
X = 1
return Vector(0,0,0)
elseif ( X==1 ) then
V2 = V - V1
V1 = V
return V2
end
end
function dotV( V1, V2 )
local Dot = V1.x*V2.x + V1.y*V2.y + V1.z*V2.z
return Dot
end
function crossV( V1, V2 )
local Cross = Vector(V1.y*V2.z - V1.z*V2.y, V1.z*V2.x - V1.x*V2.z, V1.x*V2.y - V1.y*V2.x)
return Cross
end
[/code]RE: Questions and Documentation Requests - Person8880 - 19-04-2019 Where are you looking to see New( self, ... )? The current documentation is in the editor (the ? button at the top right) and doesn't have a self parameter. Making a quaternion from an angle or entity should be simply:
Can you be more specific about what's not working?As for the vector operations, this is also in the editor documentation tab, or you can look at the GMod wiki here (the methods are the same in Starfall): http://wiki.garrysmod.com/page/Category:Vector RE: Questions and Documentation Requests - Sir_Cuddles - 19-04-2019 I was looking at "https://www.teamscm.co.uk/sfdoc/libraries/quaternion.html" I did not know the editor had a documentation tab, I just found it and this has a lot more information that I will definitely be reading through. Here is were I am using quaternions in my code, there is a chance that it might be something else that isn't working: Code: local QAng = E:toLocal(quaternion.rotationVector(quaternion.New(Ang)/quaternion.New(E))+E:pos())
EP:applyTorqueCenter((250*QAng-25*EP:getAngleVelocity())*EP:getInertia())EDIT: I just checked the documentation tab and I do not see either cross or dot product in it. As for the link you posted, when I tried "V1:cross(V2)" it was just an error, the reason why I want cross product is because of the following function I am making because I can not get the quaternions to work: Code: function aimEnt( E, Dir )
local EP = E:getPhysicsObject()
local EDir = E:forward()
local AimVec = crossV(crossV(EDir,Dir - EDir),EDir)
EP:applyForceOffset((AimVec + 5*deltaV(AimVec))*EP:getMass()*100,E:pos() + EDir*5)
endThe code works with my custom functions but if I use the V1:cross(V2) it just gives an error RE: Questions and Documentation Requests - Person8880 - 19-04-2019 Lua is case sensitive, the method is Vector:Cross( Vector ) and so on. As for the torque, Starfall uses the native VPhysics torque method which takes its direction in world space, whereas E2 uses an approximation implemented in Lua in local space. That's probably why you're getting strange results. RE: Questions and Documentation Requests - Sir_Cuddles - 19-04-2019 Okay yeah that does explain why the torque is messing up. Thank you. EDIT: I got the cross and dot products to work but is there a way to get the change in vector to work without using a custom function? In E2 I do "$V" |