Bridge Commander Central

BC Forums => BC Modding => Tutorials => Topic started by: Mario on January 10, 2011, 06:35:58 PM

Title: Becoming A Scripter 101
Post by: Mario on January 10, 2011, 06:35:58 PM
I'd like to point out that this is only a longer version of the reply: "Start learning python or start learning the basics of programming to be able to create scripted mods for BC". Since I've noticed that most people don't have a clue at all where to actually start. Don't mind my ranting as I'm trying to explain why it's so difficult to put most of what we know into tutorials as the sheer scope of it is beyond words. All I can do is point people in the right direction and help out by giving advice.

I'm going to attempt to create some basic guidelines on helping people become scripters and write some small series of tutorials. This tutorial is not for you if you already have programming experience. But to actually sum all of this up is impossible and finally what will create a good scripter is the good old process of trial and error.

First the things I'd recommend are:

Any serious developer will utilize the strengths of pylint kind of tools. In Microsoft Visual Studio features such as what pylint offers are in there by default and I strongly rely on them. Of course debugging BC is a whole new process since I can't like in VS press the debug button and I can't view in real-time what happens. So if you make a mistake in your code it's a pain in the ass process to correct it.

Now a very important question: "What does make you a scripter"?

One of the most popular resentments from people which I've noticed over the years is that some people believe that experienced modders don't want to pass on their knowledge. Every now and then a person will show up claiming that we're withholding information.
This of course is not true as you can't possibly sum years or months of experiences into a few pages long tutorial. Above all:

I know based on my own experiences that I learned this all on my own, I asked if something wasn't clear to me but I didn't blame anyone for withholding information. I speak from my programmer's point of view of course; there are people which believe that we're hiding some important secrets from all of you, to stop you from becoming a successful scripter. I don't have any comments on that since it is absurd to even comment on it.

Now let's start after my little rant. First where I'd like to get started above all are the simplest basics. I will post some short examples to point you in the right direction. If you've no clue what these are then there is really no point in attempting to write scripts. In no particular order:

Code: [Select]
pVar = "this is a string"
print pVar

Code: [Select]
1+1
int(1) + int(2)
3.0 + 4.0
float(3) + float(4)
s1 = "this"
s2 = " is"
s3 = " a"
s4 = " string"
print s1 + s2 + s3+ s4

Code: [Select]
def myFunc():
print "If you don't understand what is all of this then don't claim you're a scripter"


Code: [Select]
for i in range(1, 5): print i


Code: [Select]
i = 0
while i != 5:
    print i
    # beware of infinite loop
    i = i+1


Code: [Select]
def output(l):
    print 'start'
    for i in l:
        print i    


l = [1,2,3,4,5]
output(l)
l.remove(3)
output(l)
l.append(3)
output(l)
l.sort()
output(l)


Code: [Select]
d = {1:1, 2:2, 3:3}
for k in d.keys():
    print k

for v in d.values():
    print v

for k,v in d.items():
    print k,v

if d.has_key(1):
    d[1] = 7 # change value
    
if d.has_key(2):
    del d[2] # delete value from dictionary

print d

Code: [Select]
def x(i):
    if i <= 0:
        return 0
    retVal = x(i - 1)
    return retVal

print x(5)
To simply explain recursion in a funny sort of way. I shall quote one of the most hysterical source code comments for me personally...
Code: [Select]
def x(i):
    # If you want to understand recursion view the bottom of this method
    if i <= 0:
        return 0
    retVal = x(i - 1)
    # If you want to understand recursion view the top of this method
    return retVal
    
print x(5)

Code: [Select]
class something:
    def __init__(self, message):
        self.message = message
        
    def showMessage(self):
        return self.message

obj = something("some message")
print obj.showMessage()

Code: [Select]
import math
print math.sqrt(99)

For as long as you've no clue what these are and what these do, don't call yourself a scripter and don't even attempt to start writing code. You can try but you'll end up being frustrated. I cannot stress enough how important is to understand this.

With this very basic and short intro I shall end this tutorial as for a newcomer to scripting this can and will be overwhelming at first. So let's call it a day.

For any additional information regarding these very basics you can find in the actual python documentation. But this is where you start, this is nothing BC specific.

You may post additional questions if you have them.
Title: Re: Becoming A Scripter 101
Post by: Defiant on September 19, 2011, 02:26:20 PM
There are 2 kinds of people, one who understand binary and the ones who don't
Uhm, I know this one only with "There are 10 kinds of..."

One tiny note:
[/list]
Code: [Select]
pVar = "this is a string"
print pVar
In BC variables beginning with a p are usually used for instances of user defined Objects, s for strings. I think the tutorial should not break the style.
Title: Re: Becoming A Scripter 101
Post by: Mario on September 19, 2011, 03:10:54 PM
Each programmer defines his own style or adopts the style used by the teammates (depends really on the situation). In truth you're probably correct, but this is harmless. Hungarian Notation to me is pretty much obsolete and useless, aside from BC I've never used it. If we start this discussion it's never going to stop.
Title: Re: Becoming A Scripter 101
Post by: cordanilus on February 09, 2012, 10:41:26 PM
Yeah, I don't think I was cut out for it.  lol  I can follow some of it, edit parts of it...but that's it. :-P