Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
1 2 3 4 5 … 18 Next »
Questions and Documentation Requests
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
Questions and Documentation Requests
08-05-2015, 07:38 PM,
#1
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
Question  Questions and Documentation Requests
Got any questions about Starfall? Want a function documented? Post here and I'll try to get around to answering/documenting.
Find
Reply
08-05-2015, 08:06 PM,
#2
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Questions and Documentation Requests
I'm going to start by pre-emptively explaining input validation in Starfall.

There's 3 stages to input validation:
  1. Object validation check.
  2. Function argument type check.
  3. Function argument value check.

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().
if IsValid( Ent ) then
print( Ent:pos() )
end

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.
if IsValid( Ent ) and Vec then
EntConfusedetPos( Vec )
end

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:
if type( Vec ) ~= "Vector" then return end

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:
-- Takes the Vector Vec, and clamps its magnitude between the Min and Max values.
-- Returns Vec after modifying it.
local function VectorClamp( Vec, Min, Max )
local CurrentLength = Vec:Length()
local NewLength = math.clamp( CurrentLength, Min, Max )
if CurrentLength == NewLength then return Vec end

Vec:Normalize()
Vec:Mul( NewLength )

return Vec
end

You can also directly check for NaN values using the standard check:
local function IsNaN( Value )
if type( Value ) == "number" then
return Value ~= Value
end

for i = 1, 3 do
if Value[ i ] ~= Value[ i ] then
return true
end
end

return false
end
But in practise you should not have NaN values lying around.
Find
Reply
05-02-2016, 01:00 PM,
#3
Liizzii Offline
Moderation Neko
*****
Posts: 130
Threads: 12
Joined: Sep 2013
RE: Questions and Documentation Requests
Request: Poly's and vertexes.

also the vertex documentation need a better explanation of it's arguments than x,y,u,v

I like custard.
Sometimes I think I'm too sarcastic....
My site: http://www.theender.net
Website Find
Reply
05-02-2016, 06:37 PM,
#4
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Questions and Documentation Requests
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.
Find
Reply
19-04-2019, 03:47 PM, (This post was last modified: 19-04-2019, 04:01 PM by Sir_Cuddles. Edited 2 times in total.)
#5
Sir_Cuddles Offline
TSCM Member
***
Posts: 4
Threads: 1
Joined: Apr 2019
RE: Questions and Documentation Requests
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]
Find
Reply
19-04-2019, 04:53 PM,
#6
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Questions and Documentation Requests
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:
local AngleQuat = quaternion.New( Angle )
local EntityQuat = quaternion.New( Entity )
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
Find
Reply
19-04-2019, 05:11 PM, (This post was last modified: 19-04-2019, 05:42 PM by Sir_Cuddles. Edited 4 times in total.)
#7
Sir_Cuddles Offline
TSCM Member
***
Posts: 4
Threads: 1
Joined: Apr 2019
RE: Questions and Documentation Requests
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())
E is the entity, and EP is the entities physics object.

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) end

The code works with my custom functions but if I use the V1:cross(V2) it just gives an error
Find
Reply
19-04-2019, 06:58 PM,
#8
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Questions and Documentation Requests
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.
Find
Reply
19-04-2019, 07:06 PM, (This post was last modified: 19-04-2019, 07:12 PM by Sir_Cuddles. Edited 2 times in total.)
#9
Sir_Cuddles Offline
TSCM Member
***
Posts: 4
Threads: 1
Joined: Apr 2019
RE: Questions and Documentation Requests
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"
Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread:
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.