All language subtitles for 10. Creating An Array

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1 1

[MUSIC] 2

2

Next stop, we're going to discuss arrays. 3

3

And I'm not talking about asking your boss for more money, haha, bad joke there. 4

4

We are talking about arrays. 5

5

So what is an array? 6

6

An array stores into a variable, multiple elements of the same type. 7

7

Let's have a look at the example here, an example of how we could craft an array. 8

8

We start off with our types, so this is an integer. 9

9

You can see we have full, not full, whole numbers down here. 10

10

Same thing, full numbers, whole numbers. 11

11

If it was a float as our type, then we would have decimal place numbers or 12

12

numbers with decimal places. 13

13

We could have a string or we could have any other sort of type in here. 14

14

We use the square brackets to denote that this is an array. 15

15

And then we have a variable name, as we've done before. 16

16

This variable is going to store these particular numbers, these particular 17

17

values, in this variable, and it will store them at specific locations. 18

18

So, at location 0, and all good programming starts counting from 0, and 19

19

you can think of it of how many steps is it away from this initial value in here. 20

20

So this is 0 steps away and this is 2 steps away at number 5. 21

21

So each of these has a position. 22

22

If we wish to get access to our number 9 in here, 23

23

then we're referring to within our array, odd numbers array, the location number 4. 24

24

So back into unity, let us open up our adventure script here, adventuregame.cs. 25

25

We're gonna do a little example of an array, so we can see how it works. 26

26

First of all, so underneath my text component and 27

27

starting state, I will add an integer. 28

28

That is a, whoops, wrong brackets, that is a array. 29

29

So int, and then our square bracket, oddNumbers. 30

30

We're basically typing out what we saw on our screen 31

31

just a moment ago, = { 1, 3, 5, 7, 9};. 32

32

And then end with semicolon. 33

33

So this is the exact thing we saw previously, 34

34

int odd numbers one through to nine. 35

35

So we have declared our array and also initialized our array. 36

36

We could have stopped at this point just here, and 37

37

said ignore all this stuff down below and say there we go, 38

38

we have declared an array of type integer called oddNumbers. 39

39

And then later on, 40

40

we will say what the values of this variable is, of this array is. 41

41

But for now, we're going to start off by declaring and initializing in one step. 42

42

This is all code that we're just playing around with at the moment, 43

43

we're not gonna use this in our final game, but I'm using this to 44

44

illustrate how arrays work just within our current script in here. 45

45

So we have that, now let's go down to our start method, 46

46

and just add an extra line at start method. 47

47

Let's print out to our console, let's print out number seven from the array. 48

48

Let's go through this together. 49

49

Debug.Log( ). 50

50

Now we don't need our quotation marks cuz we're not printing out a string. 51

51

We're printing out our variables so we type in (oddNumbers) and 52

52

then within that, we open our square brackets, and we say number 3, 53

53

or we add number 3, and then semicolon. 54

54

So what this is saying is, print out Debug.Log oddNumbers variable, and 55

55

whatever is at position number 3. 56

56

Now, we're counting from 0, so 0, 1, 2, 3. 57

57

This is will be number 7, if all goes planned, 58

58

so Save over into Unity, hit Play. 59

59

Look at the console and it should say 7, as it does, fantastic. 60

60

Likewise, if we wanted to print out a string, then let's change up, 61

61

here's a mini challenge for you again, change this rray 62

62

from oddNumbers to days of the week. 63

63

And then use Debug.Log to print out, say, Tuesday into the console. 64

64

So here's a mini-challenge for you. 65

65

Pause the video now and take on that mini-challenge. 66

66

Okay welcome back. 67

67

Why is it many challenge and not a challenge, 68

68

well I guess because I don't have a slide for it therefore it's a mini challenge. 69

69

Okay so instead of this being an int, we will change it to a string, so 70

70

it's type string we will call it daysof. 71

71

Actually I'm gonna show you a trick here, I'll undo that. 72

72

In Visual Studio, if we click on the name of something and 73

73

we go Ctrl+A A, so double A. 74

74

I'm guessing it's Cmd+A, A on the Mac, apologies, 75

75

I don't know exactly what that is on the Mac, but on PC. 76

76

It is Ctrl AA, 77

77

that will allow us to rename all of the things that are called audit numbers. 78

78

So, I'm going to type in daysOfTheweek. 79

79

And you can see, its naming here, and it's also renaming there. 80

80

Because it knows, this is one and the same. 81

81

So that's a neat little trick there. 82

82

You can click Apply. 83

83

And instead of our numbers, we are going to change this. 84

84

We need our quotation marks for each of these. 85

85

We'll say, mon, whoops, I'll just type it, monday, the abbreviated version, 86

86

so we're not here forever. 87

87

{"tues", "wed", "thurs", "thurs"}; and 88

88

then I'm gonna leave it that the remaining three days of the week. 89

89

But I'll save ourselves the extra 30 seconds of typing that. 90

90

And then, what were we going for? 91

91

Tuesday. 92

92

So, this is position 0, and this is position 1. 93

93

So, we will change our reference here to 1. 94

94

Save, back over into Unity. 95

95

Give our script a moment to compile. 96

96

Click on Play. 97

97

And, then all going to plan, it will say, Tuesday. 98

98

Yes, it does. 99

99

Excellent. 100

100

So, that's the usage of arrays. 101

101

Pretty straight forward. 102

102

I'm going to remove our example that we've put in here, for now. 103

103

We don't need that for what we're doing. 104

104

Remove that and remove our Debug down here. 105

105

Arrays are super useful if we want to store multiple things in one variable, 106

106

and what is the use case for that one? 107

107

We're about to do a use case for that. 108

108

We're about to implement that in our game. 109

109

We're gonna jump here into state, and within state, what we want to do is 110

110

have a variable which stores all of our next states. 111

111

What do I mean by that? 112

112

At the moment we have starting state, let's go ahead and 113

113

create two more next states. 114

114

I'll right click up to create state, what will we call this? 115

115

We'll call this Room One. 116

116

Not a very good name for now. 117

117

We're going to go through and create our actual story pretty soon, but for 118

118

now we're doing, this is a placeholder Room 1 and I'll create a second one. 119

119

Right click, Create, State, call this Room 2. 120

120

Again, we have stunning state. 121

121

We have Room 1 and Room 2. 122

122

Room 1, I'll just write a little bit of text in here, I am in Room 1. 123

123

And then Room 2, we'll say, okay, this looks like room two. 124

124

This is placeholder, so feel free to type whatever you like in there, just so 125

125

we've got something. 126

126

If we end up, whoops, printing this out on the screen, we know that it's accurately 127

127

portraying the right particular state we're going for. 128

128

So we now have three states, starting state, Room 1 state and Room 2 state. 129

129

These are assets, these are our scriptable object assets. 130

130

And we have these three. 131

131

So if we wanted to say from starting state, 132

132

your options are to go to Room 1 or Room 2. 133

133

We wish to store that information in 134

134

a variable that has the concept of next state. 135

135

and when we look over here and states, 136

136

what that will require is that we serialize a variable called next states, 137

137

and then we create a new public method where we are returning the next states. 138

138

And that is going to be your challenge. 139

139

This is a little bit of a deeper challenge, so feel free to stop the video. 140

140

Take time to look through what we've worked through previously. 141

141

Have a look at how arrays work, and 142

142

have a good think about it, I'm gonna give you a few hints. 143

143

So if you don't want the hints, feel free to pause the video and 144

144

dive in as soon as you're ready. 145

145

The summary of what we're trying to do, 146

146

is create a public method as we've previously done in here. 147

147

This was our previous public method we've already created when called, 148

148

returns an array of next states. 149

149

So this one when it was called, it returned a string. 150

150

So this variable's a string and the return type is a string. 151

151

What we're looking to do is to return an array of next states. 152

152

So the type is states. 153

153

And here are the hints. 154

154

if you're ready, if you think that's enough information, 155

155

then pause the video and jump in now. 156

156

The first hint, is serialized array of type. 157

157

So I'm gonna change on the fly. 158

158

This should be serialized an array not serialized. 159

159

So serialized, 160

160

serialize an Array of type State called nextStates. 161

161

So that's the first thing. 162

162

We're creating our, declaring our variable, nextStates, 163

163

and we're serializing that, and it's of type Array. 164

164

And the public Public method that returns nextStates is called GetStateStory. 165

165

And the return type needs to be the same as the variable type. 166

166

Okay, so there are your clues. 167

167

Jump in, give that a shot, and 168

168

I'll see you back in here in a moment for our solution. 169

169

Okie-dokie, our first step here is to serialize a variables. 170

170

So serialize field is of type state cuz we're looking for 171

171

states, that will be within array. 172

172

We denote it as an array without square brackets, and we'll call this nextStates. 173

173

Cuz we want to know what are the next states that could comes after, 174

174

whatever our current state is, our current state is a starting state. 175

175

Now for creating our method, and the bottom of our script here public, 176

176

what is this, it's a state and 177

177

we need our square brackets because it's an array, it's an array of typeState. 178

178

Space. 179

179

We will call this GetNextStates. 180

180

No parameters. 181

181

So open and closed parentheses. 182

182

Curly braces and we will type return. 183

183

And what are we returning? 184

184

Well, we're returning our variable array of type states. 185

185

So we're returning nextStates. 186

186

And then we'll save that. 187

187

So that's creating a State Array called 188

188

nextStates, that is being returned when we call GetNextStates from our code. 189

189

One last step we are doing in this video, so well done if you've got that challenge 190

190

correct well done if you got close to that as well, we'll do one last step in here 191

191

and that is jump back into Unity, have a look at an update that we should now see. 192

192

If we click on any of these asset files, our scriptable object files here, 193

193

we can see that we now have a field called nextState. 194

194

It says size zero. 195

195

This is our array in here. 196

196

And because we've create it as a serialized array, that means we can 197

197

dynamically add, just by dragging and dropping we can add into our array, 198

198

we don't need to define all the different aspects of our array. 199

199

In our code, we can define the aspects of our array straight here in the inspector. 200

200

Now, the size we can say is four, for example, and 201

201

that will mean we're looking for four elements. 202

202

Four elements of our array that will be the next state. 203

203

We know we have 2. 204

204

So, we can tie in here 2. 205

205

That will give us 2, element 0 and element 1. 206

206

Room 1 we drag into element 0 and Room 2 we drag into element 1. 207

207

Again, we could click on the selector and then we can choose Room 1 and or 208

208

2 from there. 209

209

Now, another even easier way to do this, I'm just going to change this back to 0. 210

210

While clicking on startingState I can come up to the inspector. 211

211

There's a little lump, very little lump up in the top right here. 212

212

If you click on that, that will lock the inspector so no matter what else I click 213

213

on, the inspector will remain locked to the startingState. 214

214

That'll allow me to easily click on things without bouncing and 215

215

going to a different location. 216

216

If I had the lock off and I'm like okay cool. 217

217

Now I wanna grab Room 2. 218

218

Whoops, now I'm on room two on the inspector, and 219

219

I want to stay the inspector on starting state. 220

220

So, while that lock is on, I can click on Room 1, hold down Shift, Room 2, 221

221

drag both of those over to where it says nextStates. 222

222

Let go and it will automatically size it to 2. 223

223

And add those two elements into my array. 224

224

This is pretty handy, if you have lots and 225

225

lots of things that you want to add to an array. 226

226

You can just go [SOUND] in one spot, and 227

227

you don't have to select them one at a time. 228

228

Make sure you unlock the inspector, so 229

229

that we don't accidentally stay on on that locked on that asset fall. 230

230

Now we can have a look here, and we have our story in our startingState. 231

231

We have our nextState that we are going to go to using our array. 232

232

And in the next video, we're going to call the method that we've just 233

233

created our get next stage method, and we are going to give the player 234

234

the option of going to the nextState or the next part of our story. 235

235

So great work in this video. 236

236

Well done. 237

237

Hopefully arrays is making sense. 238

238

Again, we will be using these things over and over through out this course, so 239

239

if it's only just settling in a little bit into your head, no problem. 240

240

This will get crystal clear the longer we go through out this course, and 241

241

more we work through the contents. 242

242

So great work, I'll see you in the next video.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.