Team Spartan Cookies & Milk Forums
Proposed change to entities - 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: Proposed change to entities (/thread-777.html)



Proposed change to entities - Person8880 - 06-03-2015

I'm adding bindings to physics objects to Starfall, and I've made it so that if you try to do anything with an invalid physics object, it throws an error instead of returning nil or doing nothing.

This makes it much easier for me to bind stuff and handle the behaviour.

I want to make the same change to entities, but I'm aware this may break people's stuff. I wanted to ask what people who use Starfall regularly think of the idea, rather than go ahead and change it without warning.

Pros:
  • Using an invalid entity is immediately obvious, not hidden behind a nil return value/do nothing method.
  • Encourages stricter validity checking.
Cons:
  • Makes IsValid checks essentially mandatory, which can add boilerplate code to places.

Also, to help with this, I'm going to make IsValid a standard function in the global table, which will check for both nil values and valid entity/panel/physics object values.

Note that for now only the new Physics Object type has this behaviour.


RE: Proposed change to entities - Person8880 - 07-03-2015

Just to clarify what this means as the first post was probably not explicit enough:

Current system
--Valid entity
local Pos = Ent:pos() --Returns position
EntConfusedetPos( Pos + Vector( 0, 0, 10 ) ) --Moves the entity up 10 units

--Invalid entity
local Pos = Ent:pos() --Returns nil
EntConfusedetPos( Pos + Vector( 0, 0, 10 ) ) --Throws an error about performing arithmetic on a nil value

Proposed system
--Valid entity, same as above
local Pos = Ent:pos() --Returns position
EntConfusedetPos( Pos + Vector( 0, 0, 10 ) ) --Moves the entity up 10 units

--Invalid entity
local Pos = Ent:pos() --Throws error "Attempted to use an invalid Entity!"



RE: Proposed change to entities - TheOneAndOnlyTee - 07-03-2015

cool this'll make it easier to identify code that I've messed up lol


RE: Proposed change to entities - Person8880 - 07-03-2015

This change has gone in and will be present from the next server restart(s). If you do proper validity checks, you have nothing to worry about!


RE: Proposed change to entities - LocInt - 07-03-2015

Well I don't see any wrong in this.