Page 1 of 1

Get/Set event variables

Posted: Mon Jul 09, 2012 5:55 pm
by Ayuto
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.

Posted: Mon Jul 09, 2012 9:08 pm
by Omega_K2
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.

Posted: Mon Jul 09, 2012 11:15 pm
by your-name-here
I'm going to post a discussion on the event system. You guys should check it out :)

Posted: Mon Jul 09, 2012 11:40 pm
by Freakyy
I also agree with that. Yesterday, Ayuto and me hat a lot of fun playing with SP :)

Posted: Fri Jul 20, 2012 7:02 am
by Chrisber
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

Posted: Fri Jul 20, 2012 3:03 pm
by your-name-here
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 :)

Posted: Sat Jul 21, 2012 4:28 am
by Absolute
Just as a fyi: weapon_fire doesn't spam anymore it only fires when you actually fire the weapon (atleast in css now)