Discussions

SmileBASIC Community

ClaytonDarkClay88

06/20/2016 1:02 AM ·Spoilers

Open Closed

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.

Advertisement

Comment

This post has no comments.

  • 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.

    Yeahs1
    Played
  • 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

    Yeahs1
    Played
  • 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.

    Yeahs1
    Played
  • 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.

    Yeahs1
    Played
  • 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

    Yeahs1
    Played
  • 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.

    Yeahs0
    Played
  • 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.

    Yeahs0
    Played
  • What are arrays again?

    Yeahs0
    Played
  • 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

    Yeahs1
    Played
  • 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?

    Yeahs1
    Played
  • *a lot of this*

    Yeahs0
    Played
  • *pretty sure* I'm on a roll today. :P

    Yeahs0
    Played
  • 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.

    Yeahs0
    Played
  • I'll try :) Thank you.

    Yeahs0
    Played

Add a Comment

You must sign in to post a comment.

Sign in using a Nintendo Network ID to connect to users around the world by writing posts and comments and by giving Yeahs to other people's posts. You can create a Nintendo Network ID using your Wii U console or your system in the Nintendo 3DS family.

Use of Miiverse Details about Miiverse

Report Violation to Miiverse Administrators

You are about to report a post with content which violates the Miiverse Code of Conduct. This report will be sent to Nintendo's Miiverse administrators and not to the creator of the post.

Violation Type:

Post ID: 3DB-NBL7-BXN-3HKP-WHB-7TCR

Report Violation to Miiverse Administrators

You cannot report posts made automatically by a software title.

Edit Post

Select an action: