Imports

All other Source.Python topics and issues.
User avatar
velocity
Senior Member
Posts: 220
Joined: Sat May 10, 2014 6:17 pm

Imports

Postby velocity » Tue Jan 27, 2015 3:37 pm

I have been looking through some of the addons in here and into Source Python.

I think it's pretty crazy have many things you have to import to create even the most simple scripts :p

You really have to read up on the documentation. In this case, why wouldn't I use sourcemod instead?

Any reason for that?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Jan 27, 2015 4:31 pm

It isn't exactly 'easy' to learn SourceMod, either. You still have to learn about the same functionalities and how to use them, no matter which plugin you choose to create for. EventScripts (Python) was the same way. The design of Source.Python started out to provide a more Pythonic way of creating scripts than its predecessor, and that design is still alive and well today. Instead of teaching people bad programming habits, we strive to teach people to use OOP (Object Oriented Programming) ideas and to use proper documentation. Not that we don't appreciate what EventScripts taught us, but we wanted to eliminate the all-in-one mentality that ruled that plugin.

In all honesty, I would say blaming the number of imports and the fact you have to read the documentation are horrible reasons to not use a plugin. Everything in our design has a specific place where it belongs. Want to find out about 'player' specific functionality? Look into the 'players' package. Need to find out how to send a message and which messages you can send? Look into the 'messages' package. We also have a very friendly community, from what I have found, so feel free to ask questions if you are stuck or lost.
Image
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Tue Jan 27, 2015 8:56 pm

It clears things up... technically, Python doesn't "know" that there are any events. In fact, if you click something on the screen, an event is created and an event handler is called. The PC doesn't even know that there is an event going on, it will never, it just goes on to compute "until it dies" lol.

having that said, I'd say that explicitly importing the module makes it clear what the script is for. EventScripts, as I understood it, looks for all functions in the python file and if it finds a function name which matches an event name, like player_death, goes on to call this function with the proper arguments (userid and so on).

SP, again, as I understand it, 'registers' functions as events using the Event decorator. The function names have to be the same as the event name (I guess), but SP doesn't have to look for those in the python file, it just 'gets' them.

Imagine someone looking at some code and trying to figure out what it is (doesn't have any experience of SP or EventScripts, just pure Python).
Here, this guy can be 100% sure that player_death is an Event, because you explicitly declare it that way:

Syntax: Select all

from events import Event

@Event
def player_death(game_event):
pass
Here, he/she doesn't (at least not 100%)

Syntax: Select all

import es

def player_death(event_var):
pass
Sure you can comment things, but why all those comments if the API does half the commenting for you while providing more flexible ways of doing things?

velocity wrote:In this case, why wouldn't I use sourcemod instead?

Any reason for that?

Yep, Python! :D
My Github repositories:

Source.Python: https://github.com/backraw

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 34 guests