Methods of level loading in Panda3d (Solved)


#21

Thaumaturge: You may have to wait on your request for a example, because my script is mess right now as I,m still implementing the multiple scene function, but I will post it after I,m done though. though I think you may be right for separating functions into files. though, I,m worried about compiling, may I ask? how does panda compile games?

Do the python scripts retain their code form or are they compiled into machine code like C++, because from research, I found out that C++ does not retain it’s original form, and is compiled into machine code like assembly, so if I separated them into multiple files would the import functions fail because it is no longer python script?

So self, would need to be replaced with base then, thanks, I will use this in the future.


serega-kkz: I used showbase because I copied a lot of the roaming ralph demo’s code to jumpstart my game, I have seen some demo use Directstart, but from I can get of what you are saying is, showbase is more automatic? because you don’t have to add a method in front and just use self?


rdb: so showBase is automatic? I use global variables because they can be altered by functions, but also because they are referenced first for code needing to check for a variable before it is declared, I keep getting a “store your variables in a class” vibe, and it sounds I like a good idea, but I need to test out the class if it repeats or not first.


#22

Hahah, fair enough! Of course, you could always put together a small script to demonstrate a specific issue–such as the example that I intend to request further down this post.

You don’t need to worry about that: your imports should continue to work perfectly well, I believe. (Again, I’ve made and distributed multi-file projects myself, and so speak from experience.)

As to whether it’s compiled… I’m a little shaky on the specifics of this myself, but ultimately it’s not something that you’re likely to have to worry about. Python deals with everything below the “source code” level, and it seems to work well.

I’ll leave a more-detailed description to someone who knows the internals better than I!

Note also, by the way, that while C++ is compiled into a much lower level, multi-file C++ programs still work after being compiled.

Class instances and local variables can be altered by functions, too–it just calls for giving the function a reference to the variable in question.

This really confuses me. What is it that you do with functions and global variables that you’re concerned that you can’t do with classes? Could you show us a bit of example code–even if it’s not a whole program–that demonstrates what you mean?

[edit]

Honestly, if functional programming works better for you, then stick with it!

Myself, I find that classes work very well for me–but that may not be the case for you.

I’m not sure of how you might keep your variables organised in a functional approach to programming–I’m not as familiar with it.

I do encourage you to try out classes (i.e. “object-oriented programming”) if you haven’t previously, because you might find that they work for you. But if you have tried them, and they don’t fit well with the way that you think, then I daresay that you can stick with functional programming.

(With the minor caveat that you will encounter classes in using Panda, as Panda’s various elements are generally classes that you’re intended to create instances of.)


#23

I think you expects the panda to create classes at each iteration of the loop. The answer will be negative if you did not explicitly specify this using the task manager or the for loop. It’s also easy to check use print.


#24

But… the same would be true of a call to a function, would it not? The computer won’t do something that it’s not told to do, after all.

Unless they’re thinking of a function passed in to the task manager, being “repeated” by the task system–in which case one could just pass in a method belonging to the relevant class.

I’m very hesitant to speculate further, because I really don’t know what’s meant, and so fear that advice given under the wrong assumptions may mislead, or miss the point.


#25

Thaumaturge: heh heh heh, well, I actually don’t fully remember why I went with global variables and why I think classes don’t repeat themselves, since I have been working on this 3 months straight, but it is notion I got somewhere, that is why it is untested (I test it tomorrow though, just been vary busy adding features)

I guess you can chalk it up to laziness on my part as I have been just going forward, I do apologize for confusion though, but classes do sound better for organization though. So should I just post some code bits in my posts? or do you want a script file?

serega-kkz: no, I mean the “return Task.cont” function that allows a task manger function to repeat endlessly.


#26

Heh, fair enough! That can indeed happen, I think. :slight_smile:

Don’t worry about it! It can be easy sometimes for communication to become unclear in situations like this, I think.

However, thanks to your mention of “return Task.cont”, I think that I have a slightly better idea of what you’re getting at.

In that sense, you’re somewhat right: classes don’t “repeat themselves”–but that’s not really a problem.

(In fact, functions don’t generally repeat themselves, either: Panda’s task manager repeats them. Just as calling a function twice in your own code “repeats” it, Panda’s task manager “repeats” the functions given to it as long as you tell it to via return “Task.cont”, I believe.)

A way of thinking about classes and functions that I recall being taught, and that may prove useful to you is this: classes are essentially “nouns”, or “objects”, while functions are “verbs”, or “actions”. An object can perform an action, and just so, a class can have functions. Calling a function belonging to an instance of a class is a bit like having that object perform that action.

Thinking about it this way, one doesn’t generally “repeat” an “object”–but an object can “repeat” an “action”.

So, you wouldn’t have the task manager “repeat” an instance of a class–instead, you’d have it “repeat” a function belonging to an instance of a class.

For example:
(It’s possible that I’ve made some mistakes below, as I’m not checking that it runs. My apologies if so!)

class Cat():
    def __init__(self, name):
        self.name = name
        self.cuteness = 5000
    
    def meow(self, target):
        print target, "hears", self.name, "meow."

class Game(ShowBase):
    def __init__(self):
        # <Normal initialisation here>
        
        # Now, make a "Cat", and add an update task
        self.cat = Cat("socks")
        self.taskMgr.add(self.update, "update task")
    
    def update(self, task):
        self.cat.meow("Thaumaturge")
    
myGame = Game()
myGame.run()

The result would be Panda printing out a rapid stream of repeated “Thaumaturge hears Socks meow”, I believe.


#27

Thaumaturge: Hmm, so separating features into classes would be the better way? like if I had the environment related functions (including the related global variables) into their own class from the character functions and variables? if so, that does so good, but I lack any syntax experience to perform such a task, which is why I want to take Udamy class on python.

You are right though about the class’s non repeating nature (as well as the function), it’s the “return Task.cont” code that is doing the repeating, as it turns out that I was embarrassedly wrong about classes, because I just tested it out today, and global and class variables stay still, so the class does not update, and was a irrational fear that I got from somewhere.

And I,m sorry I got you mixed up in this weird notion got, I’ll try to be more vigilant about panda3d features in the future, also thanks for the insight, it will hopefully lead to better code.


#28

Seriously, don’t worry about it! You misapprehended–I daresay that most, perhaps all programmers have done so at some point.

I don’t know that I’d universalise so much as to call it outright better. I think that it’s better for me–but that doesn’t mean that it’s necessarily better for you. Look into it, see whether it works for you, and if so, go with it. If not, find a way that does work for you.

That seems like a reasonable pair of classes, yes. Exactly what classes you come up with might vary depending on what makes sense to you, and on the game itself. In some games I’ve had several “layers” of character-related classes; in others I’ve had just one or two.

Fair enough! I don’t know Udamy, so I’m not in a position to speak to their quality, but if they’re good, then that seems to make sense. There may be other resources out there, too.

Well, I’m glad that you did try that experiment, and gained an answer from it, then. :slight_smile:

Good luck with your continued learning! :slight_smile:


#29

Thanks, I,m learning a lot, which is good as it can assist me in the future.


#30

Well, finally after a week and half of work, and with the help of everyone on this thread, I have created the “parsing class”, a special class that can take “made up” code from a txt file and turn it into usable room data.

Sadly, Thaumaturge, I cannot upload the demo as per your request as it is too big, even when I remove the audio, it’s weighing a 3.3 MB at that, and this site reports only a 3MB max, anyways, thank you, rdb and Thaumaturge for helping me form the class, and thank you serega-kkz for the demo as it helped me greatly for the parsing logic of that class that I made.

I couldn’t have done this without you guys, and with that being said, this issue has now been solved.


#31

I’m glad that you seem to have come up with something that works for you! Good luck with the rest of your project–I hope that it goes well. :slight_smile:


#32

thanks, it is hard work, but exciting when it comes together.


#33

If you’re interested in sharing your project you should throw it up on git! Even if you’re not, if you’re not using version control right now I’d highly recommend putting it in a private repo.


#34

Don’t you need a account with them?, also are your suggesting compiled version, sorry for asking, but what is a private repo?