Coding Style

Discuss API design here.
User avatar
BackRaw
Senior Member
Posts: 413
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany

Postby BackRaw » Sun Feb 01, 2015 2:23 pm

satoon101 wrote:I would say whatever you choose works best for you. Again, these guidelines are specific to the plugin itself and not for everyone's scripts.

That's kinda what I figured. Thanks for clearing up.

satoon101 wrote:When we first started this plugin, we had thought that many people might post some good additions to the plugin itself. Since we wanted to keep everything fairly uniform, and so that we didn't have to go back through anyone's code, we decided to post this thread for them to reference. Then, if we had any issues with the formatting of the code, we could just post a link to this thread so they could update it to our standards. Unfortunately, very little was posted and what was didn't really fit with our gameplan for the specific areas that were involved. This thread still serves that purpose for anyone who does post code, either here or as a pull request on GitHub.

I think, as the plugin and its recognition grows, this thread will gain attention, too.

satoon101 wrote:Back to your post specifically. It is my intention that the next commit I make will include both m_flFlashMaxAlpha and m_flFlashDuration in the entities data.

The flashbang count (m_iAmmo.012) is already available:

Syntax: Select all

count = <PlayerEntity>.get_flashbang_count()

<PlayerEntity>.set_flashbang_count(2)


I am not sure about m_iPlayerState. I will have to look more into that property to see how we want to account for it.

Okay, I didn't notice set/get_flashbang_count was available.

Ayuto wrote:I would also like to add that using constants will make your life easier in some situations.
1. If the value of the constant need to be changed, you only need to change one occurence. If you don't use constants you would need to do that everywhere you use this value.
2. Constants also allow you to give values a name. Imagine you use the value "5" somewhere in your code. At the first glance you won't know what the value is representing. If you would create a constant for it (e.g. PLAYER_SPEED) it would be absolutely clear what the value represents.

You're right. Is it better to use #2 or #3? What would you say? =)
My Github repositories:

Source.Python: https://github.com/backraw/backraw.sp
User avatar
Ayuto
Project Leader
Posts: 1619
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Feb 01, 2015 3:43 pm

I can't say what's better. I guess this is a matter of preference. The benefit of #3 is obviously that you can find every constant in a single file. But if you use #2 you will find every constant in the module they belong to. This creates some logical structure.
User avatar
BackRaw
Senior Member
Posts: 413
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany

Postby BackRaw » Sun Feb 01, 2015 4:34 pm

True, true.
My Github repositories:



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

Return to “API Design”

Who is online

Users browsing this forum: No registered users and 1 guest