Why is my sprite's costume not changing in scratch when the statement of a function becomes true? - sprite

Why is my sprite's costume not changing in scratch when the statement of a function becomes true?
I have the following code:
For some reason it doesn't change the costume.

Change the block "play sound ...WAV FINAL until done" to: start sound ...WAV FINAL" What's happening is that the program waits until the sound is done playing to then check to change the costume

Related

How to solve error performing FM Demodulation in octave?

I am trying to demodulate a modulated FM Signal. As you can see in the code below I use fmmod to modulate the FM signal, however when I use fmdemod or ademodce then neither returns anything similar to the original signal. For fmdemod I believe it is that you can not enter freqdev as in fmmod, so it does not perform the reverse. With ademodce I have no idea why that is not working. Is there any other Octave function I can use to attain the original signal again or how do I use either one of these two correctly to do it?
See example code below:
[sound2,fs]=audioread('sound2.wav');
fc=7500;
freqdev=100;
dt=1/fs;
len=length(sound2)*dt;
t=0:dt:len;
t=t(1:end-1);
t1=t(1:end-1);
FMmod=fmmod(sound2.',fc,fs,freqdev);
FMDemod=ademodce(FMmod,fs,"fm",freqdev); %Or fmdemod(FMmod.',fc,fs) Neither is working.
sound(sound2,fs)
sound(FMDemod,fs)
subplot(2,2,1),plot(t,sound2),title('Original Sound');
subplot(2,2,2),plot(t,FMmod,'r'),title('FM Modulated');
subplot(2,2,3),plot(t,FMDemod,'g'),title('FM De-Modulated');
subplot(2,2,4),plot(t,FMmod-sound2.'), title('Carrier Signal');

I am trying to make an image stay put longer after an if statement occurs

I am trying to edit my game so that when an if statement occurs an image appears, but the if statement only happens when the object hits the wall and the ball bounces off, so the image only appears for the amount of time the if statement is active. I tried to make a delay command but after the if statement occurs it freezes the entire game for the given time.
Does anyone know how to isolate a delay command or make the image stay visible for an extra second after the if statement expires/after the ball hits the wall and bounces off???
Here are the lines of code that has to do with this:
image_set = pygame.display.set_mode()
image = pygame.image.load("image.png")
def image():
image_set.blit(image,(600,90))
if object.left == (COLLISION_RANGE) or object.right == (WINDOWWIDTH COLLISION_RANGE):
DisplayOoface()
Oof.play()
Put the code to "hide" the image into a separate function, Use the Threading package to create a new thread and pass that function in to be executed.
Within the function you can add a delay to the start of the code. When you start the additional thread within the if statement, you will have the delay you need, and then the function can hide the image.
If you do not thread this task, then python simply processes one line of code at a time. By passing off the task of waiting and hiding the image to a secondary thread, your main thread (the game) can continue functioning as needed.
https://docs.python.org/3/library/threading.html

How can make sound only play once in pygame?

When the user trigger a condition,I need to play a sound once.It is in major cycle of while,so it always play many times.Please solve the little problem.Thanks.
Include at the start of your loop the code playsound = True. Then in your loop put the following:
if playsound:
# Play the sound
playsound = False
Put your current command for playing in place of # Play the sound, it probably looks something like sound.play().

How to select random .wav/.mp3 file from folder with Garry's mod?

I've recently started Coding a program that will replace sound effects from a default directory, in the Source-Engine Game, Garry's Mod.
This is the current code:
function GM:PlayerFootstep( ply, pos, foot, sound, volume, rf )
ply:EmitSound("gear1")
return true
end
I want to emit multiple .wav Sound effects, without them overlapping, and being selected at random.
I have not found any Source helpful enough on the Internet to assist, so i resorted to Stack Overflow.
I would appreciate assistance with the topic.
You'll want to look at the file.Find function for this.
I'd recommend having a custom folder such as sound/customsteps/ where you can put all your custom sounds. I would also recommend using the .wav format for the sound files, but some others do work (.mp3 and .ogg if I recall correctly).
In your code, simply call local snds=file.Find( "sound/customsteps/*", "GAME" ) which gives you a table, then you can simply choose a random one from the list using local snd=snds[math.random(1,#snds)] and play it as you do in your above code - ply:EmitSound(snd).
Make sure you create the table of sounds outside of the GM:PlayerFootstep function, so that it only runs once. I would also recommend precaching all the sounds. You can do this by looping through the table and calling util.PrecacheSound(path) on them, like so:
for k,v in pairs(snds) do
util.PrecacheSound(v)
end
So, with all that in mind - your final code should look something like this:
local snds=file.Find( "sound/customsteps/*", "GAME" )
for k,v in pairs(snds) do
util.PrecacheSound(v)
end
function GM:PlayerFootstep( ply, pos, foot, sound, volume, rf )
ply:EmitSound(snds[math.random(1,#snds)])
return true
end
Source: personal experience

best option for background subtraction using emgucv?

can you suggest a good option for background subtraction using emgucv? my project is real time pedestrian detection.
Not sure if you still need this, but...in EmguCV, if you have 2 images of say type Image<Bgr, Byte> or any other type, called img1 and img2, doing img1 - img2 does work! There is a function called AbsDiff as well, I think it works like this: img1.AbsDiff(img2), you could look into that.
If you already have the picture of the background (img1) and you have the current frame (img2), you could do the above.
This is quite possible take a look at the "MotionDetection" example provided with EMGU this should get you started.
Effectively the code that removes the foreground is effectively named "_forgroundDetector" it is the "_motionHistory" that presents stores what movement has occurred.
The example has everything you need if you have trouble running it let me know,
Cheer
Chris
See:Removing background from _capture.QueryFrame()

Resources