1
00:00:01,930 --> 00:00:06,550
In this video, we want to work on our pause function, and this one's a little bit more tricky because

2
00:00:06,550 --> 00:00:12,730
think about it, if we pause a song, we have to know whether or not the song is paused or not when

3
00:00:12,730 --> 00:00:13,870
we unpause it.

4
00:00:14,470 --> 00:00:15,760
So and it's just one button.

5
00:00:15,760 --> 00:00:18,930
We're not clicking a pause and unpause button.

6
00:00:18,940 --> 00:00:20,470
There's not two buttons, just one button.

7
00:00:20,480 --> 00:00:23,130
So we need to do a little bit of hacking to get this to work.

8
00:00:23,140 --> 00:00:27,550
So let's come down to our buttons here and find our pause button and off.

9
00:00:27,670 --> 00:00:28,660
That's the image.

10
00:00:28,670 --> 00:00:36,240
Let's go down here, pause button right there and let's give this a command equal pause.

11
00:00:36,250 --> 00:00:41,500
Now, normally this is how you issue a command, but we need to pass something into this function when

12
00:00:41,500 --> 00:00:46,420
we click the button and we need to pass in whether or not the button has already been clicked in the

13
00:00:46,420 --> 00:00:46,900
past.

14
00:00:47,380 --> 00:00:49,390
Is our song currently paused or not?

15
00:00:49,570 --> 00:00:50,800
We need to pass that in.

16
00:00:50,980 --> 00:00:52,900
So to pass anything with a function.

17
00:00:52,900 --> 00:00:58,210
Normally you just put these parentheses and then you type in the thing you want to pass and we want

18
00:00:58,210 --> 00:01:00,160
to type in a variable called pause.

19
00:01:02,210 --> 00:01:03,290
Which we haven't created yet.

20
00:01:03,320 --> 00:01:08,180
We'll do that in just a second, but the thing about Cantera and passing in commands like this through

21
00:01:08,180 --> 00:01:14,630
a button, you can't do the normal python function thing, which is this naming the the thing you want

22
00:01:14,630 --> 00:01:16,050
to call and then passing it.

23
00:01:16,070 --> 00:01:17,820
Then you have to use something called a lambda.

24
00:01:17,960 --> 00:01:23,280
And in order to use a lambda, you just type in the word lambda and a colon and a space.

25
00:01:23,750 --> 00:01:25,370
And again, this is a lower case.

26
00:01:25,370 --> 00:01:26,450
L. It's not capital.

27
00:01:26,450 --> 00:01:28,440
Sublime text just makes it look that way.

28
00:01:28,460 --> 00:01:29,210
Drives me crazy.

29
00:01:29,780 --> 00:01:31,490
And then the rest of the stays the same.

30
00:01:31,820 --> 00:01:35,620
So we're passing this paused variable into our pause function.

31
00:01:35,630 --> 00:01:37,700
So let's go ahead and start creating these things.

32
00:01:38,530 --> 00:01:46,370
So let's come down here below our stop function and let's create pause function.

33
00:01:46,820 --> 00:01:51,080
And to do that, let's go define pause now.

34
00:01:52,040 --> 00:01:58,130
Since we're passing in something into this function, we need to account for that, so let's do that

35
00:01:58,130 --> 00:01:58,520
right here.

36
00:01:58,530 --> 00:02:00,050
Let's call this is paused.

37
00:02:01,600 --> 00:02:08,620
Now, inside of this function, we can use this variable is Porres, which will become whatever it is

38
00:02:08,620 --> 00:02:11,230
we passed in right here.

39
00:02:11,830 --> 00:02:13,390
Basic function stuff with Python.

40
00:02:13,400 --> 00:02:17,290
If you're not really familiar with Python programming, this may be a little tricky if you know a little

41
00:02:17,290 --> 00:02:17,750
python.

42
00:02:17,770 --> 00:02:18,940
This makes perfect sense.

43
00:02:19,030 --> 00:02:20,980
If it doesn't make sense to you, don't worry that much.

44
00:02:21,580 --> 00:02:23,830
It will become more apparent as we build this out.

45
00:02:23,840 --> 00:02:27,910
So we're passing this paused variable, but it doesn't exist yet.

46
00:02:27,910 --> 00:02:33,090
So let's create it and we need to do that outside of this paused function we just created.

47
00:02:33,100 --> 00:02:39,280
So right here above it, let's go create paused variable.

48
00:02:41,600 --> 00:02:48,140
Here we go, and I'm going to call Porres equals I'm going to set it equal to false.

49
00:02:48,980 --> 00:02:52,850
Now we want to use this variable all over the place, so I'm going to make this global.

50
00:02:53,180 --> 00:02:55,660
So global paused OK.

51
00:02:56,150 --> 00:03:02,420
OK, so now what we're saying here is when the program starts, right, we're creating this variable

52
00:03:02,420 --> 00:03:04,640
paused and what is it?

53
00:03:04,640 --> 00:03:05,350
It's false.

54
00:03:05,630 --> 00:03:07,880
Why or when the program starts.

55
00:03:08,480 --> 00:03:10,010
A song hasn't been paused yet.

56
00:03:10,010 --> 00:03:10,700
It's false.

57
00:03:10,850 --> 00:03:12,270
It's false that it's been paused.

58
00:03:12,570 --> 00:03:16,970
If if a song had been paused, paused would be true since.

59
00:03:17,330 --> 00:03:22,120
Since the song hasn't been paused since the program just started, we're going to set it equal to false.

60
00:03:22,400 --> 00:03:28,370
So basically when we click this button down here, our pause button, we're going to pass in that paused

61
00:03:28,370 --> 00:03:31,160
variable, which by default is false.

62
00:03:31,380 --> 00:03:34,220
So we're passing in false basically.

63
00:03:34,610 --> 00:03:34,930
Right.

64
00:03:35,240 --> 00:03:42,050
So now when we're in this function is paused is the variable.

65
00:03:42,050 --> 00:03:46,670
We're calling this inside this function just to make it different from pause.

66
00:03:47,060 --> 00:03:47,450
Right.

67
00:03:47,840 --> 00:03:50,240
And by default, it will be false.

68
00:03:51,470 --> 00:03:54,530
So instead of here, let's create another another global.

69
00:03:56,480 --> 00:04:07,760
And let's call it paused and let's say pause equals is underscore paused, OK, so now we can do some

70
00:04:07,910 --> 00:04:12,050
logic so we can say if paused equals true.

71
00:04:12,560 --> 00:04:14,230
And to do that, we just say if paused.

72
00:04:14,900 --> 00:04:16,160
That means is it true?

73
00:04:16,640 --> 00:04:20,480
If it was true, then unpause.

74
00:04:24,340 --> 00:04:25,840
Pause, right?

75
00:04:26,230 --> 00:04:27,550
So if the thing.

76
00:04:28,750 --> 00:04:35,950
Is if it's already been paused, if it's true, then unpause it.

77
00:04:36,940 --> 00:04:43,270
Else, it's false, it hasn't been passed, so if a song hasn't been paused and we click this thing,

78
00:04:43,390 --> 00:04:49,210
it means we did that because we want to pause the song so we can pause it to remember when we first

79
00:04:49,210 --> 00:04:49,990
click this.

80
00:04:50,020 --> 00:04:51,020
This is false.

81
00:04:51,310 --> 00:04:54,760
So this is not true.

82
00:04:55,000 --> 00:04:56,180
So this won't happen.

83
00:04:56,680 --> 00:04:57,580
This is true.

84
00:04:57,910 --> 00:04:58,820
It is false.

85
00:04:58,840 --> 00:05:00,000
It's true that it's false.

86
00:05:00,580 --> 00:05:01,270
That makes sense.

87
00:05:01,510 --> 00:05:02,290
So opposite.

88
00:05:02,410 --> 00:05:07,790
So a little bit a little weird, but that's how we do this.

89
00:05:07,790 --> 00:05:10,540
So how do we unpause a song, what we call pygame.

90
00:05:12,110 --> 00:05:18,260
Mixer music, it's always pygame or not music, dot unpause.

91
00:05:18,960 --> 00:05:22,970
Right now we want to set pause equal to false.

92
00:05:24,340 --> 00:05:31,510
So if paused is true, that means the song has been paused, then unpause it and then set pause to false

93
00:05:31,540 --> 00:05:33,630
because we unposted is no longer paused.

94
00:05:33,820 --> 00:05:34,780
So it's false.

95
00:05:34,780 --> 00:05:37,540
It's not paused, otherwise pause it.

96
00:05:37,750 --> 00:05:38,780
So how do we pause it?

97
00:05:39,130 --> 00:05:42,640
Same deal pygame that Mixu.

98
00:05:43,730 --> 00:05:44,630
That music.

99
00:05:46,070 --> 00:05:47,030
Dog paws.

100
00:05:48,200 --> 00:05:52,200
And then again, we want to now change paused to true.

101
00:05:52,940 --> 00:05:56,560
So if the song has not been paused, if it's false, right.

102
00:05:57,610 --> 00:06:04,390
Then posit, if it's now paused, set pause equal to true, because we just paused it, so it's true

103
00:06:04,400 --> 00:06:07,150
now here we unpause that so it's false now.

104
00:06:07,540 --> 00:06:08,680
Makes us so.

105
00:06:08,680 --> 00:06:10,180
All right, let's go and say this and run it.

106
00:06:11,840 --> 00:06:15,520
Just pull this over, add some songs you.

107
00:06:16,930 --> 00:06:17,950
Let's play one,

108
00:06:21,420 --> 00:06:22,050
was it?

109
00:06:24,110 --> 00:06:24,730
UNbased.

110
00:06:28,370 --> 00:06:28,720
Was it?

111
00:06:29,890 --> 00:06:34,130
Positive stop like another one.

112
00:06:34,410 --> 00:06:36,880
It was.

113
00:06:38,580 --> 00:06:44,850
I'm OK, and that works, so a little weird, sure, but if you have any sort of experience with Python,

114
00:06:44,850 --> 00:06:46,140
this should make sense.

115
00:06:47,220 --> 00:06:51,480
If not, I don't know, just copy the code and try to figure it out later.

116
00:06:51,990 --> 00:06:53,010
But that's all for this video.

117
00:06:53,010 --> 00:06:55,770
In the next video, we'll start to look at these forward and back buttons.
