Get/Set event variables

Discuss API design here.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Get/Set event variables

Postby Ayuto » Mon Jul 09, 2012 5:55 pm

Yesterday, I compiled a version of Source.Python to play arround with the direct access. That's a very cool thing, but I have suggestion.
At the moment we need to do the following to get/set an event variable:

Syntax: Select all

def player_disconnect(event):
# Get the player's steam ID
steamid = event.GetString('networkid')

# Set the reason to the steam ID
event.SetString('reason', steamid)


So, my suggestion would be to change it so that we can use __getattr__() and/or __getitem__() and/or get() in order to get an event variable.
The same for setting an event variable. That would make it more easier, especially for beginners, because they don't differ between types.
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Mon Jul 09, 2012 9:08 pm

Yeah, I kinda agree. Though I'd prefer getitem over getattr; this could be a pure python implementation (I guess it would well with the decorator thing I just wrote) - though we can't subclass it, i think we can simulate the class by moving the calls to the event object and implementing __getitem__ as extra functionality.
Also, setitem could be implemented in the same fashion.
your-name-here
Developer
Posts: 168
Joined: Sat Jul 07, 2012 1:58 am

Postby your-name-here » Mon Jul 09, 2012 11:15 pm

I'm going to post a discussion on the event system. You guys should check it out :)
User avatar
Freakyy
Junior Member
Posts: 4
Joined: Mon Jul 09, 2012 11:32 pm

Postby Freakyy » Mon Jul 09, 2012 11:40 pm

I also agree with that. Yesterday, Ayuto and me hat a lot of fun playing with SP :)
Chrisber
Junior Member
Posts: 21
Joined: Thu Jul 19, 2012 10:25 pm

Postby Chrisber » Fri Jul 20, 2012 7:02 am

Well, object orientation is good. But why don't you allow a lot more intuitive design?

Syntax: Select all

def player_connect(ev):
ev["reason"] = ev["steamid"] + " left the game"
# or ev.reason / ev.steamid
your-name-here
Developer
Posts: 168
Joined: Sat Jul 07, 2012 1:58 am

Postby your-name-here » Fri Jul 20, 2012 3:03 pm

Chrisber wrote:Well, object orientation is good. But why don't you allow a lot more intuitive design?

[python]def player_connect(ev):
ev["reason"] = ev["steamid"] + " left the game"
# or ev.reason / ev.steamid[/python]


Too much work. Implementing this means I have to parse the event file for types every time an event fires. This becomes very performance intensive when noisy events like weapon_fire go off constantly. I think GameEvent.GetString() is intuitive, it's just not ES intuitive :)
Absolute
Junior Member
Posts: 13
Joined: Sat Jul 07, 2012 6:48 pm

Postby Absolute » Sat Jul 21, 2012 4:28 am

Just as a fyi: weapon_fire doesn't spam anymore it only fires when you actually fire the weapon (atleast in css now)

Return to “API Design”

Who is online

Users browsing this forum: No registered users and 15 guests