arrays

  • Arrays Tutorial 1: Play a random song from a list

    Tutorial 1: Using Arrays to play a random song from a list

    We've learned the theory, now let's test it out with an example! Let's imagine we have a rad jukebox in our RPG Dream that is capable of playing a random song from a list when bumped into. The DS for that should be simple enough but uh-oh! The way our music files are named puts the numbers all over the place! They're named things like m4, m72, m2, m34, and m16.

    What are our options, supposing we can't rename the files?

    • Use a ton of DS lines to select a random song, or..
    • Use arrays to create a list of song numbers that's readable in a sequential format! Bonus: it also uses very little lines of DS to set up, and is therefore more elegant.

    This example will show you how to use arrays to accomplish this goal.

  • Arrays: The one line...

    The one line...

    There is a single array line in all of DS-cadia that does not behave like the typical array lines. Variable arrays store both the x and y coordinates of the entry in question, and when placed in a variable, copies both x and y coordinates with it. Normally, the coordinates are not treated like separate entries, but the following line is special:

    (5:390) starting with entry #, set # entries in array # to #.

    This line sets coordinate specific entries. In our previous array%Jukebox, we would have to declare entries 0, 2, 4, 6, and 8 to store the same data line (5:311) did since this line only stores half the array value. In reality, our%Jukebox array, if represented as a line of data would look like this:

    4 0 72 0 2 0 34 0 16 0

    As you can see, to properly use (5:390), you’d have to multiply the entry you’re trying to store by 2 if it's an X coordinate, or multiply by 2 then add 1 if you wanted to store a Y coordinate instead.

    To further illustrate this concept, let's use a short example to compare how to store coordinates to arrays first using line(5:311) use variable # as an array, and set entry # of it to # and then again, using line(5:390) starting with entry #, set # entries in array # to #.

Account E-Mail

Password