Series of questions regarding python and panda

hey there, i am pretty new to both python and panda3d but am very excited about what they can do together, and what i can potentially do with them…

i am working on a project that has a scripter on it that is familiar with python, but i would like to learn more about python on my own so that i can better direct the outcome of scripting, and even help write or conceptualize some of the logic and script ideas…

in any case, i figured i would just ask one question, and then go on from there… and keep adding to THIS post rather than just making individual topics for every question i have… that way all of my questions and answers can be seen in one spot… convenient…

anyway, i figured this is a basic enough question to start off with… may even be TOO basic…

i noticed the first script in the manual is just


import.direct.directbase.DirectStart
run()


now then, what is the “import.direct.directbase.DirectStart”

what does it mean, what can you do with it…
it says in the manual that “DirectStart loads most of the other Panda3D modules, and causes the 3D window to appear.”

what modules does that load?

ok, i just looked in the panda files, and found the direct start file in there at

C:\Panda3D-1.5.3\direct\src\directbase

i looked inside the file, and it said this…

print ‘DirectStart: Starting the game.’

from direct.showbase import ShowBase
ShowBase.ShowBase()


so, i figured that the directstart modules task, is simply to print something on the screen and then import another module…

am i right?

yes, plus it sets up showbase.

also, i have found the NEXT module, the one that is loaded by DirectStart, called ShowBase

i found it in this directory…

C:\Panda3D-1.5.3\direct\src\showbase

now my next question, since ive opened the showbase file, and found it to actually hold the BULK of the info contained in directstart, how do i utilize the functions that are defined in showbase?

i feel like i have done a good job finding out what i have so far… im hoping that my questions lead to more understanding among beginners, in how to understand the way that the scripts work with each other…

and what can be done with the specific modules, and how to import them and use them appropriately…

im already getting a better idea so far…

i recommend for people to go into their file directories, and look for the directstart file, and also the showbase file, and open it with your python editors, and take a look at what is in them… i think it may help people understand what is going on when they import modules…

but anyway, back to my question, can someone help explain the showbase module, and what can be done with it…

all classes are documented, in code and here panda3d.org/apiref.php?page=ShowBase

I would not recommend people to go look at files and folders because panda3d has 880,000 lines of code. Understanding 1000 lines per day would take you 2.5 years to get through them all!

I do recommend looking at the samples first, modifying and changing them. Look in the manual find some thing interesting to add to the samples. After you run out of manual try the reference to try to figure out how those components work. Only when you need a deeper insight into how a component works i recommend looking at the code.

i have looked at the beginner tutorials, and what i am trying to do is basically find out how panda works from the ground up… i understand that it would take years of coding to go through the code, and im not suggesting that every beginner looks through every line of code, what i am suggesting, is that certain things be CLEAR… like for instance, what DirectStart does… we have clarified that… it starts ShowBase, now i feel like if i can figure out what ShowBase does, then i will know more about how panda works overall… and that way i can understand what i am doing, when i import showbase or directstart or any other module…

my question at this point, is what does ShowBase do?

i looked at it, and it seems to define a whole bunch of new methods… is that all that modules are? just collections of methods that are specially defined in that module?

and if that is the case, then why would it hurt for beginners to understand the basics behind how the modules work, by taking a quick look…
if anything i think it just lets beginners understand what those little snippets of code are actually doing when you import modules, and remove some of the mystery behind it for the beginner…

but STILL, can someone explain what Showbase does, help me out here, am i on the right track? i see that it does QUITE a bit, but give me a context for understanding how to code with it, or refer to it in my codes…

i looked at that link you posted, and the most info it could tell me on any of those methods is that they are all “undocumented functions” which really doesnt help me to understand it…

i think that elaborating on these issues will help beginners understand much better how panda works overall…

hmm… im thinking i should rephrase my question to maybe be less broad…

can someone briefly explain these first few functions in showbase?


__audioLoop
def __audioLoop(self, state)

__collisionLoop
def __collisionLoop(self, state)

__dataLoop
def __dataLoop(self, state)

__doStartDirect
def __doStartDirect(self)

__igLoop
def __igLoop(self, state)

init
def init(self)


even if this seems advanced to a beginner, i feel that the best way that i will learn personally, is by just getting my feet wet and diving in head first from directstart, which means diving also into showbase as well…

Those are the different internal tasks ShowBase loops through every frame.
Though those are internal and not meant to be used externally.
You basically access the global ShowBase object using “base”, for example
base.disableMouse()
base.screenshot()
base.toggleWireframe()
base.taskMgr.run()

ok, so since there are many different functions that are called by base, im going to spend some more time figuring it out, and if i find something out worth mentioning or come up with something new to ask, then i will update this… until then, thanks for your help everyone…

Just wondering really quick…

i have been browsing the Reference section, and i am trying to learn how to code things to work correctly… now then, as i currently understand

Functions are specific tasks, that are used by methods…

methods are basically a broad task, or range of tasks that are defined by classes…

and classes are specific collections of methods and functions contained in specific modules…

is all that correct?

this implies a structure in scripting that could probably be made more clear to beginners, to help them learn…

so am i right about all that, and can someone help me to understand in general how functions, methods, and classes relate to each other, and how to code those relations properly…

crash course…

These terms all come from Python, as well as other object-oriented languages.

In Python, a “module” is a single .py file. It often contains a single class definition with the same name as the module file. Sometimes there are multiple classes defined in a single module.

A “class” is a common concept of object-oriented languages. It is an association of data and code that operates on that data. There is a further distinction between a “class”, which is a definition, and an “instance” or “object”, which are concrete manifestations of a class. For instance, “Honda Civic” is a class of cars, but that green car over there is an instance of a Honda Civic. There is only one class “Honda Civic” but there are many instances of Civics all over the world.

A “function” is a body of code with an entry point, a set of arguments, and a return value. When a function is associated with a class it is usually called a “method”, but often (especially in Python) these two terms are used interchangeably.

In the Reference section, there is a tab for “Classes”, which lists all of the classes that are documented here, and you can see the methods for each class; another tab for “Methods”, which shows the same list of methods and classes, but this time it is sorted by method name, and you can see the class that defines each method; and finally, a tab for “Functions”, which is really the handful of functions that are not associated with any particular class.

If these concepts are unfamiliar to you, you would probably do well to spend some time studying object-oriented programming in general, and Python in particular. :slight_smile:

David

no, im good… i understood it all quite well…
excellent use of allegory as well…

i would like to be able to put together a tutorial for beginners to gradually learn more and more about the language, rather than building tutorials of complete games, i figured i would just write codes that do specific things, and teach specific concepts…

im thinking, since text output is a pretty basic concept even for beginners, i was thinking it might be good to show how to script a text based program, or something like that… a VERY basic one, that beginners could learn from, and create more detailed ones out of…

it would show examples of creating variables, and giving them values, asking for user input, and changes in variable values happening upon that input, also creating content based on variables to be printed on screen for the user to read…

i think this could give some beginners some solid ground at the beginning of their learning experience, and considering the only thing that needs be imported is DirectStart, it looks to be pretty simple to make everything clear and easily understood by a beginner…

i will start working on that…

u know this brings back an excellent point I made about the manual and its slight lack of the “hello world” granted that “hello world” is supposed to be just that…saying hello world in a programming language by printing such! anyway there was the “old” begginers tutorial that was provided as a class intro by carnegie mellon! this was, to my guess, a “education packet” if it may be called such. I think providing a link to this packet would be beneficial and explain panda in a more better way! especially since it basically teaches you the very basics of loading a model, textures, animations, setting up keyboard functions such as moving the object, and basic collision detection. all of which can be used to start a very primitive “first” program aka your very own “hello world”

i agree, in fact i think i saw you bring this up on another topic, something about the long lost ultimate lesson for beginners…

it sounds great… very useful… maybe we can make a new one from scratch, and get it out there, so that people can start working with it, and learning from it…

right now, i am going over the samples that come with panda, and am adding my own notes to help myself understand what is going on… i may post my changes sometime in the future, but i like your idea…

i wouldnt mind helping to make it…

great idea! like i said before in your topic I had trouble with you email! anyway the lost tutorial needs to be found and I’m searching for it!

my email is plato_03@yahoo.com

i am going to delete my email address from here once you send it, so spammers should WRITE IT DOWN right now, while they got the chance…

just kidding…

but seriously, im looking forward to it… i think we should be able to do quite a bit to help make an awesome game, and also help beginners to understand the basics, and get to the point where they can learn things on their own, without getting in over their heads…

I have a new question… right now, i am working on a very basic “hello world” program…

what i would like to do is just write a program that writes “hello world” onto the screen using the OnscreenText function

now then… i have a code here… and it seems to compile correctly, but whenever i run it, there is no text… what am i doing wrong? could someone look at the code and point out what needs to be changed?


import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText

def init(self):
self.title = OnscreenText(text=“Hello World”,
style=1, fg=(1,1,0,1),
pos=(0.8,-0.95), scale = .07)

run()


for some reason, the indents dont show up when i copy and paste into here, but there are indents…

anyway, thanks for your help, people… its much appreciated.

You have defined a function call, oddly, init. This is normally the name used for the constructor of a class, though you did not place it within a class.

In any case, you never call that function, so its code doesn’t get executed.

You probably meant to place that function within a class, like this:

import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText

class World:
  def __init__(self):
    self.title = OnscreenText(text="Hello World",
          style=1, fg=(1,1,0,1),
          pos=(0.8,-0.95), scale = .07)

w = World()

run() 

Because init() is the name of the constructor, which is called implicitly whenever you create an instance of the class, the line “w = World()” calls init().

David

Incidentally, use the Code tag to ensure that the indents in your code show up in your post.

David

RIGHT!

exactly, thank you very much.