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

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 14 15 16 17 18 Next »
Proposed change to entities
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
Proposed change to entities
06-03-2015, 08:25 PM,
#1
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
Information  Proposed change to entities
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.
Find
Reply
07-03-2015, 10:00 AM,
#2
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Proposed change to entities
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!"
Find
Reply
07-03-2015, 11:59 AM,
#3
TheOneAndOnlyTee Offline
GMod Admin
Posts: 755
Threads: 47
Joined: Oct 2013
RE: Proposed change to entities
cool this'll make it easier to identify code that I've messed up lol

Steam Profile
My Discord Server
Need help with E2 or SF? , just ask me and i'll try to help.
[Image: 98Dkcoz.gif]
Find
Reply
07-03-2015, 03:03 PM,
#4
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Proposed change to entities
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!
Find
Reply
07-03-2015, 03:30 PM,
#5
LocInt Offline
Long gone
****
Posts: 489
Threads: 91
Joined: Aug 2014
RE: Proposed change to entities
Well I don't see any wrong in this.

тѕсм.Person8880 hovers the nerf bat over Tetryon damage
Website 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.