Python Problem

I have a big Python Problem and i hope You can help me. :frowning: How can i make sure, that a specific Script runs first? EG: Make five Objects named 1; 2; 3 … an give them an Always - and a Python Controler. Now make five Scripts named 1; 2; 3 … (containing a Print Order) and connect them to there Objects. Start the Game. Now You see, that the last added Script was running first. And here, the Frog has Curls! That’s not always so. The “Start Position” is conditioned from Object and Script Number of addition. How can i make sure, the (eg) second Script always start first, independently how many Scripts and Objects i add in the Future.
In Callis G-Blender Documentation is a Standart Methode for LogicBricks: setExecutePriority(int). What’s that? I played around with this, but nothing happens. Please Help!

Thx’n Cu, Doc

Give the object a property called script. Start it on zero, and set the first script hooked up to a property sensor of “script equal to 0”. In the script, have it increment the script prop at the end of the script (object.script += 1)

Attach the other scripts up to prop sensors in the same way, for each number down the line, and add the incremement to the bottom of each script.

But Doc wants to call each script from a different game object don’t u?

OK heres what u do:

Put the following lines at the bottom of the first script:


GameLogic.script1done = 1
GameLogic.script2done = 0
GameLogic.script3done = 0

now in the second script do this:


try:
  if GameLogic.script1done == 1 \
  and GameLogic.script2done == 0:

    #put your code for script 2 here
    GameLogic.script2done = 1

except:
  GameLogic.script1done == 0:
 

then in the third script put this:


try:
  if GameLogic.script2done == 1 \
  and GameLogic.script3done == 0:

    #put your code for script 3 here
    GameLogic.script3done = 1

except:
  GameLogic.script2done == 0:
 

And keep doing that sort of thing for each script you need. Set the first script up with an Always sensor with pulse mode OFF, and all the others with pulse mode ON.

Thats what worked for me, hope it helps you!

Keith. 8)

Thanx for Youre Help Guys. I tried that, but the Result is like before. Damned! I think, the Solution of a “first run Script” will not fix my Problem. I try to explain it. Maybe, there is a complete different Solution. I’m still working on a Scene-Jumping-Script. And it worked realy fine till last Week. It was possible to jump between Scenes in Half-Life Style. With saved Propertys and Object Positions. Realy Cool and eay to use. But last Week, i had a totaly System Crash. (Have You ever seen an burning Computer?) Now i have a complete new Machine wich is much faster then the old one. And here is my Problem: Each Scene in my Game have an linked Actor Model. When i touch a special Switch in a Scene, the Script stores the Probertys, Positions and Orientations of all used Objects incl. the Actor and his “Jump Position” and switch to the new Scene with a setScene-Actuator. When starting a Scene, it’s always be reset, and the Script have to set the current Actor (back) to the Jump Position. On my old Machine with G-Force 2 MX, the Actor “resetting” was faster than the Cam shows the new View on the Monitor. That means: Actor walk on Switch - The View freeze - And goes on. But now with an G-Force 4 TI4600, the View was faster than the “resetting”. And for one or two Frames i can see the Actors Camview from his start Position before he’s being “resetet”. The Result is an ugly Flash in the Jumping Sequence. So, i thought, if the Reset-Script runs first of all, i can save a couple of Milliseconds to make the Reset faster than the View, like before. Setting Variables in the GameLogic Module or Propertys take to much Time also, and will not fix this Flash. So, i thought changing Bleders Scripting Sequence could be a Solution. I mean, Blender runs Scripts one by one. Moving my Script to the first Place of this “Execute-List” would make Propertys and other Stuff needless and it would not waste any Time. An other Solution could be the Possibility, that linked Objects share there Positions and Orientations as there did while editing. (Hm, i think that’s an other Story.) I don’t know what i can do else. Maybe, one of You Guys have an Idea or know about someone who did something similar.

Thank’s for reading this little Story :slight_smile:
Cu, Doc

Thats a very interresting problem, one that i may end up having with my game when I get that far. No solution immediately springs to mind. Forcing the scripts to run in a particular order as I showed you wouldn’t help here, cos when the next scene loads it will load in its initial view, but you can’t copy the properties back into the actor until the scene has fully loaded and is already sitting in its initial view.

All i can think of is this work around: Instead of using different scenes for your levels, use 1 scene with the level meshes far apartfrom each other, and use a python script to move the actor and camera to the correct position in the scene using the setPosition() function. Quite a messy way of doing it I know but its all I can think of.

Unless…It might be possible to have each level on a different layer in the same scene, and then u just change the active layer using python. But im not sure u can change the active layer in the middle of a game. Can u shed any light on that saluk?

Nope, you can’t change the active layer. I was going to go this route with my game, but I think I am going to have all the objects parented to the level mesh on a hidden layer, then have the script add the new level to the right spot, then delete the old level. If it overlaps right, and adds it to the right spot, it will make it seem like nothing even happened.

I’m not sure if blender has to load all of the objects and meshes that are in a non-active layer though, I think the scene method would definately work better memory-wise. If the character is linked, doesn’t that mean if you move him to the right spot before switching scenes he will be at the right spot? Hmm, I don’t think playing with the order will fix things. What you need is a way to show the last frame of scene 1 on top of everything until scene 2 is done loading then take it away. You know how half-life has: “loading” but its like the game is freezed while the next part loads? This actually might be possible, with the take screenshot command, if the filename is the same as a texture you have on a plane, and the texture is NOT packed. I seem to recall discussing something like that before, but I don’t remember the outcome.

If all else fails, the best method I would suggest is to just have a loading screen that completely covers the screen until the next scene load script has finished.

Theres an easier way to do it that I just thought of. You would need 3 scenes: the first level scene, the second level scene, and another scene containing a simple plane textured with the ‘loading’ texture.

Heres what happens:

1)The first level scene adds the ‘loading’ plane scene into the foreground
2)it then adds the second level scene into the background
3)the first level scene then removes itself half a second later
4)the ‘loading’ plane scene removes itself after a small amount of time.

You could even forget about the ‘loading’ plane scene totally if u wanted, its just cosmetic now. Providing theres no background showing in the first level scene, the user wouldnt notice the second level scene being added, and the half second delay or whatever would give the second level scene enough time to position itself correctly.

This is all assuming that background and foreground overlay scenes aren’t removed when the scene that called them removes itself - one of my fears. I haven’t got around to testing that yet, but i hope it doesn’t remove overlay scenes cos my game would be bu_ggered if it does. Do u kno the answer to that saluk? and while your at it…

Q1)can foreground scenes add there own foreground scenes infront of themselves?
Q2)can background scenes add their own background scenes behind themselves?
Q3)if a main scene creates a foreground scene which in turn creates a background scene, would that background scene replace the main scene or would it appear infront of the main scene but behind the foreground scene?

no further questions the witness may stand down! :smiley:

thanx anyway 8)

A loading Screen make only Sens, if the Jump-Process takes at least 5 or more Seconds. In my Game, it takes only 1 Seconds. So i would have a “LoadScreen-Flash”. :frowning: I think the best and cleanest Way is the Screenshoot Solution. I had this Idea too, but that’s not possible, yet. Sure, we can make a Screenshoot and save it to HardDisk. But in this Case, we need a Shoot witch is stored in Memory. Writing to Disk and reloading would taking to much Time too. And a Texture would only be updated if i start the Game new. I don’t know, if there is a direct Solution to change a GameTexture. Hmm … wait … i think i’ve go an Idea. If i store each Scene in a new *.blend File and load it after jumping. I mean: Actor walk on Switch - The Script saves all saveable - make ScreenShoot and save to HD - Load and start new Scene File - show the ScreenShoot File on a OverlayPlane on StartUp - Reset Actor and Objects - Kill Plane an let the Game go on. Hmm … could this be a Solution? Only if the ScreenShoot File would be updated in Memory by reloading a Scene. I think i have to try this, but i’m not sure. What do You think?

Actually what gorgan mentioned makes a lot of sense:) As long as tthe current scene has a complete background, you can easily load the next scene in as a background scene, prepare it, then kill the foreground scene. The only problem is blender might not like having two scenes with linked objects.

Try it though

Nope, blender has no problem with multiple scenes having linked objects. I usually have the main character of my games linked to all of the level scenes.

What I mean is having linked objects between scenes that are both running at once. This could cause problems, I’m not sure if they designed it to be able to do it. But like I said, try it and see if it works.

:o But i already have a Background Scene - the Skybox. I use a OverlayScene too, for the InventorySytem. If i add to the MainScene witch has a already BGRScene (SkyBox) a new BGRScene, what will happen with my current BGRScene? Would that not be replaced?

I’ll test that and try to answer my own Q’s when I’ve got time.

That reminds me. I remember reading a post from you saluk on blender.org about a problem you had getting a python-driven sky box working in a background scene. You said that there was a lag of a couple of frames between the main camera and the skybox camera caused by the lag time of executing a python script. I dunno if you solved that after all or not but i came up with a solution:

Instead of moving the main camera directly, move an empty instead. Then use the one python script to copy the empties position/orientation to both the main camera and the skybox camera. There will be the same lag time between the cameras and the empty, but because both cameras will have exactly the same lag time, there won’t actually be any lag time between the cameras themselves. :smiley:

another thought on that, if the answer to my Q2 is yes…

…then you can get the background skybox scene to add the second level scene behind itself. 8)

Yeah, have the skybox be the one to add the new scene then. Gets kind of tricky though, but I’d like to see what you come up with because I might use something such as this for my game.

Although after some tests I’m kind of feeling like having much larger levels than planned, and I think they will be seperated by distance so I wont need to change the characters start position.

Yeah, gorgan, that’s a good idea. Just give the lag to both cameras:) The other thing you can do is make sure both cameras behave in exactly the same way (same logic bricks etc, perhaps copy the character minus meshes to the other scene). But this is a bit less reliable, and probably slower.

Whe I started making an FPS, I just attached the mouse script to the camera, and the empty it was parrented to, and linked them both to the skybox scene. It worked perfectly. That’s why I don’t think linked objects will be a problem in multiple scenes.

thats probably the simplest way but i dont like linking objects together with logic bricks, i think its a messy way of doin things. thats whyi prefer to use python whenever possible, although sending/recieving messages are a good and clean way of achieving things without having to resort to python. :slight_smile:

I didn’t mean linkes logic bricks, I meant linked objects, by selecting the objects, pressing Ctrl-L and chooseing ‘to scene’.