scripts for CD player

Hi guys. I’m from the next door forum, python scripting, so I guess this’s my first post here. I’m also a rookie with the engine, and I’m having a lot of troubles with that. I 'd enumerate, but I’ll just tell the thing I’m doing: a CD-player :Z

Well. I’ve an object with a property: ‘song’. Then, simplyfing, I can define a AND controller, link to a CD actuator for playing 1 song, and for example, a Keyboard sensor. All runs OK when I press space, it’s wonderful!

But I want to use the property (remember, ‘song’) for playing any song. So I create this script:

import GameLogic

ctrl=GameLogic.getCurrentController()
obj=ctrl.getOwner()
act=ctrl.getActuator('P'+str(obj.song))
GameLogic.addActiveActuator(act,1)

CD-play actuator is named ‘P1’

Then a bizarre thing occurs: Not only the sensor detects twice (if I add a ‘print’ line to the code, it appears twice), but worst: the CD goes crazy, it tries to start the song EVERY FRAME, and as a result it sounds th-th-th-th-th…

Please, I need a help. Anybody made a CD-player?

hello,
it seems to me that use the cd actuator is realy unstable if you use scripting with it, but i made this withourt using anny script, mehbe it can help you

http://www.ikx.no/nj/files/homepage/files/CD-PLAYER.blend

edit: updatedhttp://www.ikx.no/nj/files/homepage/files/CD-PLAYER_new.blend

Well, I 'll try not to use Python, really it’s given me some problems. Anyway, I guess your player will be very useful to me, thank you!

No problem klopes

Glad to help :slight_smile:

A keyboard sensor fires both a positive pulse and, when it’s released, a negative pulse. Both initiate the python script. Add this to your script:

if keyboardsensor.isPositive:
blablablba

you mean:

if keyboardsensor.isPositive():
    blablablba

otherwise it would always be true
(and the lack of spaces would confuse python, get an error: expect indented block)

Yeah, the Python script running on both true and false pulses seems to be the biggest problem that catches newcomers.

It sometimes seems unintuitive, but it lets the script do different things for example when a key is pressed and when it is released.

(Sorry por the pause :smiley: )
Yeah, it’s totally clear. Thanks to all.
But now I’ve considered my work completed, and there’re some troubles i can’t understand. Let’s see:
The program is a MusicCD menu for a musical group. It has a tracks window, and a videos one. There’s also a web launcher option, to go to the web site.
For both the web and the video options, I wrote a couple of scripts. They invoque to ‘os’ library and make os.startfile(filepath), which launches the file as it was double-clicked.
Well, all works perfectly in the blender environment, but as always, the problems appear when made the standalone.
-I know external python lybraries can´t be used, but os works… almost. It u click on an option that uses such scripts (“Visit the web” or “watch videoclip”) in a computer without Python, it makes a console error (I can’t remember which, sorry) but just THE FIRST TIME!. The second click works fine!
-The other hard problem is about win98: it doesn’t work at all. It says that it isn’t a valid win32 appl. (Maybe because it has been created with w2000?)

I hope some help from you, please… I offered to make this program for the musicians for nothing, just like a Blender defender… :Z telling them: WATCH wath blender can do! AND I HAVE TO FINISH IT as soon…! :expressionless: