トピック
Clayton DarkClay88

DIM, VAR, and DATA

I've been programming for about three months now and I still don't fully understand DIM, VAR, or DATA. Could someone explain this stuff to me? I have a feeling that if I learn this, I could advance my own programs.
6そうだね
プレイ済み
返信[1]
親投稿
Aaron Krondelo
DIM is short for dimension. so , DIM list[10] creates a variable (which is an array) called list. Array indexing starts at 0, so the first reference is list[0] and the last is list[9]. Each index can hold a value. You can add or remove elements from the array, increasing or decreasing the total amount too.
1そうだね
プレイ済み
返信[2]
親投稿
Aaron Krondelo
Arrays are useful because of their flexibility, they are very useful in FOR loops. Because we can use the loop variable to iterate over the entire array: FOR i=0 TO 9 list[i]=x x=x+1 NEXT
1そうだね
プレイ済み
返信[3]
親投稿
Oscar PwnageBlock
As Aaron said, DIM is used to declare arrays, which can have up to 4 "dimensions". In multi-dimensional arrays, each primary element is itself its own array with its own elements. Such that... DIM AR[2,2] ...will declare a 2-dimensional array, where you must first call the sub-array and then the element of the sub-array. In other words, AR[0] and AR[1] will each be a 2 element array.
1そうだね
プレイ済み
返信[4]
親投稿
Oscar PwnageBlock
You can then call each individual element by specifying the element in the sub-array. Like this... ARR[1,0]=10 You can declare a string array by writing a dollar sign after the array's identifier. Like this... DIM NAMES$[10] There are various commands that operate over arrays, but you can probably study them own your own. The most basic ones are probably PUSH, POP, SHIFT and UNSHIFT.
1そうだね
プレイ済み
返信[5]
親投稿
Oscar PwnageBlock
VAR is really only necessary when specifying OPTION STRICT, which won't let you declare variables on the fly. This means that you are forced to declare each variable you will use using VAR. To use VAR, you simply specify the identifier of the variable you want. In other words, if you want a variable named FOO, you'd have to declare it like this... VAR FOO
1そうだね
プレイ済み
返信[6]
親投稿
Oscar PwnageBlock
You can declare multiple variables by separating each identifier with commas. Like this... VAR FOO, BAR You can also specify the type of a variable by suffixing certain characters... No Suffix - FOO - Will declare as decimal by default. Percent Sign - FOO% - Will declare as integer. Numeral - FOO# - Will declare as decimal. Dollar Sign - FOO$ - Will declare as string.
0そうだね
プレイ済み
返信[7]
親投稿
Oscar PwnageBlock
You can specify OPTION DEFINT so that identifiers without suffix declare as integers by default. DATA's usage isn't really too obvious or apparent. It is mainly used to save constant struct-like data, which can be recovered using the READ instruction. In other words, it is mainly used as a way to save specifically structured data inside your program's code, such as enemy data, for example.
0そうだね
プレイ済み
返信[8]
親投稿
Clayton DarkClay88
What are arrays again?
0そうだね
プレイ済み
返信[9]
親投稿
Oscar PwnageBlock
An array is a collection of elements, each that can be accessed as an index of the array. It can hold multiple elements, but all of them must have the same type. Here's a visual example... DIM ARR[5] 'Declare an array of size 5. ARR[3]=7 'Assign 7 to the element in the array at index 3 ___ ___ ___ ___ ___ |_0_|_1_|_2_|_3_|_4_| < Indices |_0_|_0_|_0_|_7_|_0_| < Elements and their values
1そうだね
プレイ済み
返信[10]
親投稿
Clayton DarkClay88
Wow, a lot this is hard to comprehend. But I'm pretty it helps a lot. Btw in DIM, what does it mean by dimensions?
1そうだね
プレイ済み
返信[11]
親投稿
Clayton DarkClay88
*a lot of this*
0そうだね
プレイ済み
返信[12]
親投稿
Clayton DarkClay88
*pretty sure* I'm on a roll today. :P
0そうだね
プレイ済み
返信[13]
親投稿
Aaron Krondelo
Its okay dude it is a lot, but it's not as hard as it seems. Don't give up, use the code i showed you and experiment with how it reacts. Dimension only really makes sense when there is more than 1. Dont worry about 2-dimensional arrays until you understand basic 1-dim arrays.
0そうだね
プレイ済み
返信[14]
親投稿
Clayton DarkClay88
I'll try :) Thank you.
0そうだね
プレイ済み