プレイ日記
SomeThing… DJZouk2017
Can anyone explain how arrays work in the simplest way possible? Help will be highly appreciated.
2そうだね
プレイ済み
返信[1]
親投稿
SıмΞоп SimeonW
Imagine a long list of boxes Each box contains one number inside But all the boxes are hooked together like a train It's just a way to store a bunch of numbers together, they're extremely extremely useful If you want 5 items You initialize it with DIM myArrayOfNumbers[5] To set the last item in the array to 3.14, type myArrayOfNumbers[4]=3.14 You subtract one from your index, the 5th item is 4
4そうだね
プレイ済み
返信[2]
親投稿
SıмΞоп SimeonW
You know what a string is, right? The string: "Hello World!" is literally just an array containing 12 letters So you could even type: VAR myString="Hello World!" Typing myString[6] gets the 7th letter, which is "W"
2そうだね
プレイ済み
返信[3]
親投稿
SomeThing… DJZouk2017
Could you give me some examples of arrays in code?
1そうだね
プレイ済み
返信[4]
親投稿
SıмΞоп SimeonW
^
2そうだね
プレイ済み
返信[5]
親投稿
raimondz raimondzz
Motivation: In Smilebasic, arrays let you store a "dynamic" amount of elements. A static defintion is something like this: VAR SP1,SP2 You see, there are two elements. You need to write another variable to create another. With array: VAR SP[0] Here is an array with 0 elements, but if you use PUSH then you can have a dynamic number of variables without changing the code.
3そうだね
プレイ済み