Basic Python Questions

Hello Again,
I recently posted a request for some tutorials, and the only response I got, turned out to be very helpful. (Thank you whoever you are, I’m sorry I don’t remember your name, I have a horrible memory for names, but thank you anyway) Ive been going through the manual, and the demos that came with Panda3D, and I’ve actually learned a lot.
I have a few questions though, just about basic programming, and any help would be very welcome.

  1. What are arguments for a function?

    • I know where they go, but I don’t know what they look like, or what they do.
  2. Could someone please just dissect and explain (quickly) the parts of the following code?

    • direct.directBase.directStart
    • pandaActor = Actor.Actor(“models/panda-model”,{“walk”:“models/panda-walk4”})
  3. In the code: pandaActor.setScale(1,1,1) the line setScale, the dot means its a property of pandaActor right?

This may be useless, but I think it will help me remember the code better
Thank you for the help youve already given me,
I’m sorry if these seem kind of stupid, but they really would help me alot.

Thank You
Peter

Edit: digimikeh was the one who helped me, Thank you!!!

Another Quick Question:
If I wanted to create a lot of ships, with different attributes, could I create a list with each of the ships attributes in it, ie, for every ship 0 - speed 1 - attack 2 - fov etc, and then use those values like: when I hit the forward button find value [0], for my ship, move forward at the speed specified by value [0].

Is that how I would do that?

Thanks
Peter

  1. I’ll do my best…

Say you wish to create a function that adds two variables together, i.e. A + B, and prints the result.

Since you don’t know what values A and B will be (you don’t even know if they are numbers), you should be using “arguments” in your function.

#create a function with arguments A and B
def add(a, b):
    print a + b

#now we can add numbers together...
add(2, 5)        #prints 7

#... or strings
add('hel', 'lo') #prints hello

You can also create default arguments (aka. parameters). Say we want to increment A by one if B is not specified…

#if b is not specified, default it to 1
def add(a, b=1):
    print a + b

add(5, 5)   #prints 10
add(5)      #prints 6

#you can also use keywords...
add(a=50)   #prints 51

#but this will cause an error, because you can't add string + int
add('v.')

I’m sure some of the online tutorials can explain it better than I can!
pytut.infogami.com/beginners_functions

The first line imports a Panda3D module so you can use Panda3D related classes.

The second line creates an “Actor”. This is usually a 3D character model loaded from EGG files. In the example, we load the pre-defined EGG, “panda-model”. Usually it would look more like “models/myModel.egg”. We’ve also defined an animation called “walk” and linked it to the pre-defined EGG, “models/panda-walk4”.

The dot roughly means “look in pandaActor’s class (Actor) for a function called setScale”.

The term “property” is generally not used for functions.

As for multiple ships, that sounds like a complicated way of doing it. A cleaner way might be to use a list of dictionaries, where each dictionary represents one ship.

ships = [
    {name="Ship 1", speed=5, attack=35},
    {name="Ship 2", speed=20, attack=15}
]

An even cleaner way would be to use classes.

If you’re having trouble with these basic concepts, maybe you shouldn’t be starting off with 3D! :wink:

Thanks, you really did a good job of explaining them.
I’m not so much having trouble, with the concepts, rather, I was just trying to clarify. I am a beginning programmer.
However, I didn’t know that Panda could do 2d games, so I probably will make a 2d game first.

Thank you again for all your help!
Peter

Panda3D is a 3D game engine. You CAN make 2D games with it but that’s not the intention. As a beginner it will be much easier starting with 3D than 2D in Panda.
If you need an easy start with 2D, how about trying pygame?

Also, I think it’s much easier learning Python’s basics before going for complex libraries, really.

I do know pythons basics,
I was really just trying to clarify,
And I have learned from past experience that I have to start small,
You really don’t have to worry about my next post asking for networking help for my mmo game,
That’s already happened in other places,
I’m not completley new to game development, just programming
Thank you anyways for your help, you really did help me alot,

Thank You
Peter

2D is pretty tricky in Panda. But, if you’re feeling ambitious, a simple 3D game really shouldn’t be too hard.

Good luck. :slight_smile: