DSiWare Forum

Topic: Petit Computer Tutorials

Showing 21 to 40 of 98

AuthorMessage
Avatar

Linput

21. Posted:

i need a tutorial on how to use the d-pad for my OS to select categories on the menu, and the A button to go into that categorie or play that game. :I

Edited on by Linput

Linput-3DS friend code: 4725-8494-2702
Pokemon White 2 pal-pad code: 1979 9213 55

I'm currently looking for some peeps to make SALLY a website, facebook, and email. If anyone does this u will be mentioned as a producer in the SALLY OS credits! :)

AuthorMessage
Avatar

Linput

22. Posted:

NVM

Linput-3DS friend code: 4725-8494-2702
Pokemon White 2 pal-pad code: 1979 9213 55

I'm currently looking for some peeps to make SALLY a website, facebook, and email. If anyone does this u will be mentioned as a producer in the SALLY OS credits! :)

AuthorMessage
Avatar

Linput

23. Posted:

OH btw if someone could teach me how to make an AI chatting thing for my OS, that would be great. Also, could this tutorial plz be in a QR code so i can mention u in the credits of SALLY, my OS?

Linput-3DS friend code: 4725-8494-2702
Pokemon White 2 pal-pad code: 1979 9213 55

I'm currently looking for some peeps to make SALLY a website, facebook, and email. If anyone does this u will be mentioned as a producer in the SALLY OS credits! :)

AuthorMessage
Avatar

smartman789

24. Posted:

I just made a website for Petit Computer tutorials.
Here's a link: http://petitcomputertutorials.webs.com/
I hope you guys can make it a place where people can learn a lot about programming in BASIC.

smartman789

AuthorMessage
Avatar

heatguts

25. Posted:

to linput 14:

check my os. its inspired off of yours, and i intend to put you in "special thanks"
but yeah, it has button controls.
LOCATE 14,0
PRINT"(First menu item)"
'repeat for each item
@LOOP
B=BUTTON(1)
IF B ==1 (UP) THEN IF SEL(SEL is the selection) >1 THEN SEL=SEL-1
'same for down, with the IF SEL>1 to IF SEL<(max menu item)
LOCATE 14(I spaced out my x values),SEL(So if SEL is one, it will be one, or if two, it will locate two)
PRINT "-->"
IF B==16 THEN GOTO @SELECT
GOTO @LOOP

@SELECT
IF SEL==1 GOTO @(Menu item one)
'And so on.

Edited on by heatguts

So what if there's no Mega Mans in Metroid?
That doesn't mean we can't have metroids in Mega Man.

3DS Friend Code: 4511-1723-4299

AuthorMessage
Avatar

IAmSpike

26. Posted:

Alright, I'm just gonna make a quick thing on how to assign DATA to an array. (WARNING: Lengthy post.)

A quick run down on arrays:
Let's say, if you set an array like this:
DIM WIT$(20)
(hehehe, dim wit)
Then in the WIT$ variable, you could store 20 values, from WIT$(0) to WIT$(19), as PTC starts counting from zero.
If you set it like this:
DIM WIT$(20,20)
Then you'll have 20 values each within those 20 values. Let's see it like this:
20x20=400 values
If you set WIT$ like above, then set a value:
WIT$(19,0)="derp"
Then the first value of the 20th first value (I call it that as I can't think of anything else to call it) would be set to "derp".
Now, if you then did this:
WIT$(19,1)="herp"
Then the second value of the 20th first value would be "herp".
Now, do this:
PRINT WIT$(19,1)" "WIT$(19,0)
If you did it correctly, "herp derp" should appear on the console.
Remember: You can't set an array to the same variable twice! This will result in an error. In order to set another array to the variable, use a CLEAR command to wipe out all variables.
Now that you (hopefully) now know how arrays work, let's get on to the main entree.
First, set an array:
DIM VNAME$(X,Y)
Where 'VNAME' is the name of your array, X is the first dimension and Y is the second.
For this tutorial, let's just use one dimension to keep things simple. Also, our array needs a name of course... well, you can't go wrong with "MARIO"!
DIM MARIO$(3)
Now we can set 3 values to MARIO$. Now, for the DATA!
DATA "NES"
DATA "SNES"
DATA "N64"
(Yes, those are the names of Nintendo's classic consoles.)
Now, let's use a FOR-TO-NEXT loop:
FOR I=0 TO 2
This will repeat the loop 3 times until I=2. Confusing?

Code in loop being executed 1st time: I=0
Code in loop being executed 2nd time: I=1
Code in loop being executed 3rd time: I=2

Remember, as I said before, PTC starts counting from zero.
Now, to set the DATA to MARIO$.
FOR I=0 TO 2
READ MARIO$(I)
NEXT
Now, before I confuse you too much, let me explain READ.
READ will read a piece of DATA and assign the DATA to a variable. A single READ command will read a single string of DATA. That's why we need to use several READ commands to read several strings of DATA, and this is best done with a FOR-TO-NEXT loop.
Say, we omitted the FOR-TO-NEXT loop altogether and only left the READ command. It would only read the first DATA statement, and since I=0 because there's no FOR-TO-NEXT loop, MARIO$(I) will result in MARIO$(0), and the READ command will assign the "NES" data to MARIO$(0), leaving MARIO$(1) and (2) blank.
Remember, X variables will record numbers, and X$ variables are alphanumeric, so they record strings. Blank X variables will have a value of 0, and blank X$ variables will simply be blank, period.
If we make the READ command happen another time, it will advance to the next DATA statement, and set "SNES" to MARIO$(1), provided we set the READ command to set it to (1) and not (0), either manually or though the FOR-TO-NEXT loop. Repeat it a third time, "N64" will be set to MARIO$(2), following the same rules as mentioned before.
Also, you should set a CLEAR command at the beginning of the code, so you can run the program more than once and not confuse PTC with a duplicate definition. Our code should now look like this:

CLEAR
DIM MARIO$(3)
DATA "NES"
DATA "SNES"
DATA "N64"
FOR I=0 TO 2
READ MARIO$(I)
NEXT

Now, in order to see if it worked, we should print out the MARIO$ variable's values. Change te FOR-TO-NEXT loop to this:
FOR I=0 TO 2
READ MARIO$(I)
PRINT MARIO$(I)
NEXT

Now, run the program. If you did this correctly, you should get this:

NES
SNES
N64
OK

I could go into more detail, but my brain hurts too much. And if you still don't understand what I'm saying, I don't blame you. I'm terrible with words.

Edited on by IAmSpike

Previously Philip.

The most paranoid person on the net!

3DS Friend Code: 0559-7022-5853

AuthorMessage
Avatar

Linput

27. Posted:

Wow based off mine? That's awesome! Anyways, could somebody help me with a breakout game I'm making? It won't have the bricks to break at the top, it's just to help me learn to make games. I need help with the sprites. I don't know how to move them with the d-pad, and don't know how to make he sprites different sizes (like the ball and the paddle). I ALSO don't know how to do sprite collisions or make the ball act like, well, a ball. :/

Linput-3DS friend code: 4725-8494-2702
Pokemon White 2 pal-pad code: 1979 9213 55

I'm currently looking for some peeps to make SALLY a website, facebook, and email. If anyone does this u will be mentioned as a producer in the SALLY OS credits! :)

AuthorMessage
Avatar

ZombieChiggers

28. Posted:

sorry linput14 but i only know ANSII art but as i get learning on sprites i could help you then if someone hasnt already
BTW i am trying to update my DIRECTORY OS by putting buttons in and i dont know how either

Cameron Stover VVVVVVVVVVVVVV ALSO VVVVVVVV and i like trains (BOOM!) also minecraft and trollface!
INFECTED. NEW ZOMBIE

3DS Friend Code: 4854-7026-5042

AuthorMessage
Avatar

-Angel-

29. Posted:

I'm writing tutorials for PetitComputer, and they start with the BASICs (get the pun?) then go to the more complex stuff. Depending on when you read it, it might be unfinished, or done. I'm adding to it as I learn, myself. Here's the URL:

http://www.petitcomputerbasic.blogspot.com

Also, here's the first part to it, to get you started. But, I won't post EVERYTHING here, just the first part, then you can just visit my blog. :D

PART 1 Learning Some Basic Commands For Your First Program:

In this tutorial you will be learning SMILEBASIC, a programming language. SmileBoom says that you are using BASIC, but they're wrong. BASIC is a family of programming languages, many versions that are very similar to each other have been created. SMILEBASIC was created by SmileBoom, but it's very similar to other BASIC programming languages. So, if you were to write a program with something that used another type of BASIC, then you'd probably still be able to understand most of it.

So, let's start with the basics (< See the pun there? The programming language is SMILEBASIC.) then we'll keep working up until it gets to the really complex, complicated stuff. So, you're basically about to learn a different language, in fact, you are, this is just a programming language. So, this will be different than just simply learning "Hola" means "Hello." But, once you get the hang of it, and you are able to control your DS and make something happen, you'll feel like you are so powerful, and can do anything with that little stylus in your hand!
So, I bet you're wanting to learn how to do, and get started, on something! Well, let's start with one very simple command: the print command. This command is used to print text in your little program. So, pull out your DS, open PetitComputer, and go into Edit mode. In the first line type this:

print "I'm learning my first command!"

Don't forget the quotes, because if you just have, "print I'm learning my first command!" then there'll be an error. So, after you've typed this, go into Run mode. Chances are, nothing happened. Well, that's because you need to run your little program you've got started. You can do this by typing, "Run" then pressing the A button, or pressing Enter. Then this should pop up:

I'm learning my first command!
OK

So there you have it! You did it! But don't worry, if this didn't happen, that's okay. Just go back and make sure you did everything correctly. If you want something other than "I'm learning my first command!" to pop up, then just replace the words below:

print "Type whatever you want here"

Way to go! You've learned one of the many, many commands on PetitComputer! :D
Well, I'm sure you're getting annoyed with the:

PetitComputer ver2.2
SMILEBASIC 1048576 bytes free
(C)2011-2012 SmileBoom Co.Ltd.
READY

What this is is just what version of PetitComputer it is, the programming language, how much space is free, and the copyright. Lastly the, "READY" is just stating that the program is ready to operate. If you want to get rid of this, and all other text on your program, type in in run mode:

CLS

That's all you have to do. Then, all that text will disapear, and only, "OK" will be left. But be careful! It'll get rid of ALL the text, so if there's something important you want to keep, don't do this! (I honestly don't know what you would want to keep on your DS screen though :P) So, if you wanted to have everything erased, then some text to pop up you would type this in edit mode:

CLS
print "I don't know what to put in these quotes"

Then go into run mode and run it. Then all you should be left with is:

I don't know what to put in these quotes
OK

Now that's much neater isn't it? No I'll show you how to save and load your program. First, make sure everything's the way you want it in Edit Mode. Once everything's proofread, go into Run Mode and run it. Then type in:

Save "Test"

I saved it as "Test" but, you can call it whatever you like. Then to load your program simply type in Run Mode:

Load "Test"

It's as simple as that! If you forgot your file name, then press the X on the upper right and return to the Home Menu (But make sure you saved your work first if you were doing something; if you don't it'll be lost!). Then click View Gallery and all your programs, along with the sample ones, are in there. So if you called your program "Test" You'll see it as, "PRG : Test".

I think that'll be all for the first part of this tutorial! Thank you for reading, I hope this has helped you on your quest to making programs! :D

Try to accomplish this before going to the next part:

1. Clear your screen
2. Print something on your screen with the print command
3. Save your program
4. Be happy that you made a program! ^-^

Edited on by -Angel-

-Angel-

AuthorMessage
Avatar

ChangeV

30. Posted:

Here are 3 simple ways to slide text window.
all 3 shows basic idea of using different methods(sprite, BG layer, Graphic layer)

they simply put(and slide) window on top of grass field(which is rear BG layer).
and text output is simply done by PNLSTR command.

press any button to open and close text window.

here is sprite version.
Untitled

ACLS
CLEAR

'turn off bottom panel.
PNLTYPE "OFF"

'make some grass field.
BGPAGE 1
BGFILL 1,0,0,31,23,33,8,0,0

'select lower screen for sprites.
SPPAGE 1

'make 64x32 sprite with white color (&HF).
'sprite bank name for lower screen is "SPS0" and "SPS1".
'64x32 size sprite is 32 blocks of tile.
CHRINIT "SPS0"
FOR I=0 TO 31
CHRSET "SPS0",I,"F"*64
NEXT

'setup 2 big 64x32 sprites.
'set order of priority to the behind of console.
'so text will appear on top of sprites.
SPSET 0,0,0,0,0,1,64,32
SPSET 1,0,0,0,0,1,64,32

'scale 200%
SPSCALE 0,200
SPSCALE 1,200

'put them outside of bottom part of screen.
SPOFS 0, 0,192
SPOFS 1,128,192

@MAINLOOP

'wait for button press
FOR I=0 TO 1:I=BUTTON():NEXT

'move sprites up slowly using interpolation time.
SPOFS 0, 0,128,10
SPOFS 1,128,128,10

'wait until sprite has finished moving.
FOR I=0 TO 1:I=!SPCHK(0):NEXT

'put some text
PNLSTR 1,18,"This is first line.",14
PNLSTR 1,20,"This is second line.",14
PNLSTR 1,22,"This is third line.",14

'wait for button press.
FOR I=0 TO 1:I=BUTTON():NEXT

'erase text with blank
PNLSTR 0,18," "*32,14
PNLSTR 0,20," "*32,14
PNLSTR 0,22," "*32,14

'move sprites down slowly using interpolation time.
SPOFS 0, 0,192,10
SPOFS 1,128,192,10

'wait until sprite has finished moving.
FOR I=0 TO 1:I=!SPCHK(0):NEXT

GOTO @MAINLOOP

it uses 2 big (64x32) sprites and they act as window.
sprite's priority has changed, so window sprites appear under the text.
by the way, you can set/change/load sprite for bottom screen.
sprite bank name for bottom screen is "SPS0" and "SPS1"
for example: LOAD "SPS0:MYSPRITE"
(note:unlike upper screen which has 512 sprites, bottom screen has only 118 different sprites.)


here is Graphic version.
Untitled

ACLS
CLEAR

'turn off bottom panel.
PNLTYPE "OFF"

'make some grass field.
BGPAGE 1
BGFILL 1,0,0,31,23,33,8,0,0

'select lower screen for Graphic.
GPAGE 1

'set Graphic priority to the behind of console
'so text will appear on top of Graphic layer.
GPRIO 1

@MAINLOOP

'wait for button press
FOR I=0 TO 1:I=BUTTON():NEXT

'start drawing line from bottom part of screen.
'fill upward.
'since filling with single line is too slow,I used x4 thick filled line.
FOR I=192 TO 128 STEP -4
GFILL 0,I,255,I+3,15
VSYNC 1
NEXT

'put some text
PNLSTR 1,18,"This is first line.",14
PNLSTR 1,20,"This is second line.",14
PNLSTR 1,22,"This is third line.",14

'wait for button press.
FOR I=0 TO 1:I=BUTTON():NEXT

'erase text with blank
PNLSTR 0,18," "*32,14
PNLSTR 0,20," "*32,14
PNLSTR 0,22," "*32,14

'erase window by drawing line with clear color 0.
'starting from top part of window. erasing downward.
'it will look like window is moving down.
'for speed, i used x4 thick filled lines.
FOR I=128 TO 192 STEP 4
GFILL 0,I,255,I+3,0
VSYNC 1
NEXT

GOTO @MAINLOOP

it simply draws white filled box on bottom.
as you draw more filled box upward, it will look like sliding window.
window box is erased with another box with clear color 0
Graphic layer's priority has changed, so Graphic window appears under the text.


here is BG version.
Untitled

ACLS
CLEAR

'turn off bottom panel.
PNLTYPE "OFF"

'select lower screen for BG.
BGPAGE 1

'make some grass field on rear BG layer..
BGFILL 1,0,0,31,23,33,8,0,0

'make window box just outside of bottom part of screen.
'use foreground BG layer, so it will hide grass field.
'using white blocks.
BGFILL 0,0,24,32,31,15,0,0,0

'and you can add cool window border frame if you want..
BGPUT 0,0,24,532,1,0,0
BGFILL 0,1,24,30,24,536,1,0,0
BGPUT 0,31,24,533,1,0,0
BGFILL 0,0,25,0,30,539,1,0,0
BGFILL 0,31,25,31,30,537,1,0,0
BGPUT 0,0,31,535,1,0,0
BGFILL 0,1,31,30,31,538,1,0,0
BGPUT 0,31,31,534,1,0,0

'this BG layer will wait outside of bottom part of screen and is ready to scroll up.

@MAINLOOP

'wait for button press
FOR I=0 TO 1:I=BUTTON():NEXT

'scroll foreground BG layer up slowly using interpolation time.
BGOFS 0,0,64,10

'wait until foreground BG layer has finished moving.
FOR I=0 TO 1:I=!BGCHK(0):NEXT

'put some text
PNLSTR 1,18,"This is first line.",14
PNLSTR 1,20,"This is second line.",14
PNLSTR 1,22,"This is third line.",14

'wait for button press.
FOR I=0 TO 1:I=BUTTON():NEXT

'erase text with blank
PNLSTR 0,18," "*32,14
PNLSTR 0,20," "*32,14
PNLSTR 0,22," "*32,14

'scroll foreground BG layer down slowly using interpolation time.
BGOFS 0,0,0,10

'wait until foreground BG layer has finished moving.
FOR I=0 TO 1:I=!BGCHK(0):NEXT

GOTO @MAINLOOP

it uses foreground BG layer and use it as window.
draw window box just outside of bottom of screen.
(you can add cool frame on window layer if you want)
it waits outside and will scroll up/down as needed.

ChangeV

AuthorMessage
Avatar

randomous

31. Posted:

So @ramstrong said I should put this here instead of on the main thread, so here it goes.

Untitled

I made an auto-formatted dialog-box function set with a demo for Petit Computer. You know when you have a bunch of text that you want to output, but if you just keep printing and printing, it gets cut off at ugly places (like the middle of words) and just doesn't look right? This program is an example of how to make text fit within a box without knowing the contents of said text. This example code contains some functions which allow you to:

-Bring up a dialog box @SHOWDIALOGBOX
-Hide the dialog box @HIDEDIALOGBOX
-Clear the dialog box @CLEARDIALOG
-Make the dialog box wait @WAITDIALOG
-Show the text contained within SAY$ @MAKEDIALOG
-Show a yes/no box which "returns" the user's choice @YESNOCHOICE

Basically, showing/hiding/clearing/waiting aren't very exciting (but still necessary). The part that really does what you want is MAKEDIALOG. To use MAKEDIALOG, just put the text you want to print into the variable SAY$ and then use GOSUB @MAKEDIALOG. MAKEDIALOG will then "parse" (kind of) the variable SAY$ and figure out where it needs to cut off the dialog and move to the next line, and when it needs to halt and wait for the user to continue when the box is full. YESNOCHOICE can simply be called with GOSUB @YESNOCHOICE. After it is run, the variable CHOICE will contain the user's action. 1=yes, 0=no. The code contains a short demo which shows how to use the various functions and such. The demo will run just by starting the program, so don't feel like you have to add anything in order to see something happen. Feel free to use it for any of your games.

UntitledUntitledUntitled

The image shown at the top can be done by simply storing the entire saying into the string SAY$, for instance:

SAY$="Here is an example of some really long text. This is all just one long thing located in SAY$."
GOSUB @MAKEDIALOG

Notice that what I actually put in SAY is longer than what appears in the picture. This is because the dialog box saw that it could not fit the entire string into the box, and so it is waiting for user input (A or B) before printing the rest of the contents of SAY$. After you set the variable, just call MAKEDIALOG, like I've done above.

Edited on by randomous

randomous

AuthorMessage
Avatar

randomous

32. Posted:

Here's another post someone wanted me to put here:

I've been doing a lot of testing to see just how Petit Computer handles certain things in terms of speed (because my village game is slowing down when I'm trying to get more than 6 fish to swim around). For instance, if I execute something a bajillion times, what slows down the program the most? If you've taken courses in computer architecture and computer programming (or just know some stuff about it), you probably know about some of the basic things that cause slowdowns, such as mispredicted branches, stalling due to memory, etc. However, this is an interpreted language, so the things that slow us down are a little different. Let's take a look:

I tested the instructions that I thought would have the most performance impact first (since they do in other forms of BASIC), which were the "interrupt" instructions GOSUB and GOTO. I found that although these two instructions do incur a constant overhead, the size of the function you're jumping to and the distance to the function have no impact on performance whatsoever. The cost is extremely negligible too, at only about 1/1000 of a frame for each call to GOSUB (meaning you could call a thousand empty GOSUBs each vsync). The thing that struck me the most was that the distance to the destination of the GOSUB or GOTO has absolutely no impact. I guess Petit Computer quickly preparses your program and gets the exact jump destination so it doesn't have to search for it every time (I know some forms of BASIC actually DO search for it).

Next I tested the "heavy" operators, which are division, multiplication, and modulus. Amazingly, multiplication and modulus ran at exactly the same speed as addition and subtraction, meaning that Petit Computer probably makes sure that they all take the same amount of time. They all take about 1/5000 of a frame. Division takes slightly longer, but it's not by much (10-20%). Now about AND and OR... they actually take longer to execute than addition and subtraction! What??? So my next test was code size.

I figured code size would have some performance impact (because BASIC is interpreted and it needs to read every single character of code every time it wants to execute), but I tested it just to see. The results are unfavorable: comments and empty lines can actually increase execution time by a considerable amount! A SINGLE empty line costs around 1/10000 of a frame, which may not seem like much, but ten empty lines is about the same as a jump into a function. This is silly, I want my empty lines so I can format my program! At least comments are about the same: each comment costs 1/10000 of a frame, no matter how long it is. However, you also incur the cost of the new line, so be careful. A comment is then about 1/5000 of a frame if it is the only thing on the line. Here's an interesting thing to note: spaces just don't seem to count at all. So indentation is perfectly acceptable, but if you have empty lines, the DSi goes OMG I NEED TO PROCESS! The lesson: mash up as many lines as you can into a single one if you're grasping for speed.

This next one follows pretty logically from the previous, but variable names also impact performance, but much less than a new line. Each character in a name is about a quarter of a new line, so 1/40000 of a frame. But, if you're trying to cram as much as you can into a line, then shorter names might be better anyway (even if they're harder to understand).

So it also turns out that assignments are as expensive as GOTOs/GOSUBs, coming it at around 1/1000 of a frame as well. This means that having an assignment to get rid of some operations is only useful if the assignment gets rid of 5 operations (since each operation is 1/5000).

Well here's a pleasant surprise! COS and other trigonometric stuff is only twice as expensive as addition (1/2500 of a frame)! That's nice, considering I rewrote large portions of my code to reduce the number of cosine functions I called. Oh well. FLOOR is about 1.5 times as expensive as addition, which is about 1/3333 of a frame.

Well, it seems like the lesson here is get your program done with the least amount of code/assignments/operations as you can. For instance, don't try to improve your speed by replacing a modulus (power of 2) with an AND (power of 2 - 1), because although the latter is usually faster, in this form of BASIC the single operation [modulus] is actually faster than the two operations [AND and subtraction]. Don't have empty lines and long variable names unless you're not stressed for speed and want to be clear. Don't be afraid to use GOSUB/GOTO which are sometimes expensive in other BASICs. Well, sorry for rambling and taking up forum space with a bunch of pretty useless stuff. Hope someone gets a use out of this!

randomous

AuthorMessage
Avatar

GraphicGenius

33. Posted:

Romano, please friend me on my 3ds. I already entered your code so PLEASE ENTER MINE.

If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?

3DS Friend Code: 1478-3545-5136 | Nintendo Network ID: GreatGamer123

AuthorMessage
Avatar

thecrow

34. Posted:

I need help moving sprites I've tried the ones on this site and others plus tried changing them around but nothing has worked

thecrow

AuthorMessage
Avatar

randomous

35. Posted:

Uhh so here's yet another MML guide. This isn't an in-depth tutorial, just a sort of "quick start". Also, there are other ways to write MML in Petit Computer, but I'm going to do it the way I think is easiest: using DATA portions. This tutorial assumes that you have basic music experience, such as the ability to read music and understand simple notation/musical concepts (like scales). It also assumes that you know what a DATA section is (it's just a way to store data in textual form. There, now you know!). If you're ever lost at a particular Petit Computer command, you can look it up in the Petit Computer Manual. If you're not sure about octave designations, you can look here (I forget them all the time too).

So, we'll start with an empty program. The most basic stuff we're going to need right now is BGMCLEAR, BGMSETD, and a DATA section headed by a label. Here's what it'll look like:

BGMCLEAR 128
BGMSETD 128, @MYSONG

@MYSONG
DATA 0

The first line says "Whatever song you had as song 128... well I don't care about it. I want it GONE". Song 128 doesn't exist yet, but it's still a good idea to clear it just in case (just like clearing your variables at the start of your program). The next line says "Alright, go out and find @MYSONG and shove all that data into song 128". Well, if you look down at the label for our song, you'll see just one piece of data: 0. This represents the end of our song, so you should always stick that at the end. If you run this program, it doesn't really do anything. Let's start slow and add just a single note: C. What C will it be, some of you may ask? Well, we'll see.

BGMCLEAR 128
BGMSETD 128, @MYSONG
BGMPLAY 128

@MYSONG
DATA "C"
DATA 0

I added 2 lines: BGMPLAY 128 just tells the program to play the song 128. That's the song we're filling up, so it should play... well, our song. I also added DATA "C". Notice that the C is in double quotes: all MML should be surrounded by double quotes (making it a string type), except for the 0 at the end. It's very important that you DON'T put the 0 in quotes. So, go ahead and run the program. If you did it right, you should hear a nice Piano sound playing "middle C" (that's octave 4 if you're looking at that chart I linked to). This is rather important: this means that Petit Computer defaults to a piano and that it defaults to octave 4. But what if you don't want a piano? Well, let's look at the manual: if you jump down to page 40, you'll see the start of a very important table: the sound list. This isn't the usual "BEEP" sounds, but special MML sounds. If you look at the very first one, you'll see that it's an Acoustic Piano. That's the sound we just heard in our program, but let's change it to.... a Vibraphone (sound 11). Let's add one extra line to make it a Vibraphone, along with adding more notes:

BGMCLEAR 128
BGMSETD 128, @MYSONG
BGMPLAY 128

@MYSONG
DATA "@11"
DATA "CDEFG"
DATA 0

The line I added was DATA "@11". The @ tells the MML to start using the specified instrument from now on. What this means is that you can stick an @ followed by an instrument in the middle of a series of notes and it will switch instruments right there. Cool, right? Well, it's not always useful, so let's play our music. It should play the lower half of the C Major scale in a Vibraphone sound (not that it matters, it's just notes rising). Notice that I squashed all the notes together; in MML, this is how you do it. Some of you may start to wonder "Hey, there are multiple notes named A, B, C etc. How do I tell it to play one in a different octave?". Well, let's change the one line with the notes to look like this:

DATA "CDEFGAB<C"

If you play it, it should be the regular old C Major scale. That < in there tells Petit Computer to go up to the next octave. Remember, octaves start on C, and changing the octave wherever you want means that ALL notes following will be raised to the next octave. For instance, if we were to extend that line again:

DATA "CDEFGAB<CDEFG"

If you play your song now, you'll notice that the following DEFG after the < are higher than the original ones. This is because we went up to the next octave. Try moving the < around in that sequence of notes to see how it changes. So what about sharps and flats? Well, they're + and - respectively in MML. For instance, if we want to play the F Major scale instead, we'll change our DATA line to:

DATA "FGAB-<CDEF"

Remember, F Major has 1 flat (B flat), and that's exactly what we've put in MML. The flat/sharp follows the note, so it's read "B flat" or "B minus" if you like. Also notice where the < is this time: it's still before the C, but it's not in the same place as our C Major scale. Remember, the octave starts on C, so C is the first note in an octave. This means that if we just stick "C" there without having <, it will play a C lower than the "FGAB-" we had previously, which isn't what we want in a scale. Note that you don't ALWAYS need the < in front of a C, it's just when you're crossing an octave boundary. The opposite of < is >, which lowers the octave. Here's the whole F Major scale then:

DATA "FGAB-<CDEFEDC>B-AGFA<CFC>AF"

If you play it, you'll hear the standard "concert" version of the scale, in which you ascend, descend, and then do the same with the arpeggio. Next, we should probably add some note lengths. Right now, everything has been the default length, which is a quarter note. If you want to set the length of a note, just follow it with the number specifying the length. The first link has a list of all the lengths. For instance: 4=Quarter note, 8=Eighth note, 16=Sixteenth note, etc. OK, let's make "Mary Had a Little Lamb":

DATA "E4D4C4D4E4E4E2D4D4D2E4G4G2E4D4C4D4E4E4E4E4D4D4E4D4C1"

Yuck, look at all those 4's. Remember, 4 is the default note length, so you don't need to put it. Those 2's are half notes, and the 1 at the end is a whole note. The length of the note should always follow the note itself. What if we want to change the tempo, volume, and starting octave? Let's make our "Merry Had A Little Lamb" rather fast and really high (but a little quieter):

BGMCLEAR 128
BGMSETD 128, @MYSONG
BGMPLAY 128

@MYSONG
DATA "@11T240O6V80"
DATA "L4EDCDEEE2DDD2EGG2EDCDEEEEDDEDC1"
DATA 0

Woah, I changed a lot! Let's start at with the first: I added some stuff to the DATA line that had our instrument. Now we've got T240 which tells us to go at 240 beats per minute, O6 which tells us to start up at octave 6 instead of octave 4 (look at the chart to see how much higher that is on the scale), and V80 to bring down the volume. Volume can range from 0 to 127, so 80 is... uhhh we'll say 2/3 volume. Next, on the next line I added "L4" and removed all the 4's. The L4 tells Petit Computer that notes without a length should default to this length. You can use L commands wherever you want, and it'll only affect the notes following it (until another L is reached which changes it). Try inserting L's followed by a length at various places in the song to see how it changes it. Notice that the E2, G2, and C1 don't change even if you mess with the L's, this is because the L only alters notes that don't have a length. Let's jump ahead a little bit:

BGMCLEAR 128
BGMSETD 128, @MYSONG
BGMPLAY 128

@MYSONG
DATA ":0@11T240O6V80"
DATA "L4EDCDEEERDDDREGGREDCDEEEEDDEDC1"
DATA ":1@0T240O4V100"
DATA "L4EDCDEEERDDDREGGREDCDEEEEDDEDC1"
DATA 0

That was quite a jump, so let's look at each change individually. The first change was the line immediately following the @MYSONG, I added a :0 to the beginning. Petit Computer can play 8 streams of music simultaneously, so I'm telling the Vibraphone part to fill in the first stream (which is 0). This is the default, which is why we didn't need it before. However, if you look, it looks like I've duplicated the song. But, it you look at the third data line, you'll see :1, which means that all the data following it should go into the second stream (which is 1). Also notice that the second stream is a different instrument, louder, and in a different octave. If you go ahead and play the song, you'll hear that the first stream plays just like it always did, but the second stream is now the piano (from the @0 on the third data line) and louder (from the V100 on the third data line). This shows that each stream is fully independent: whatever you do on one will not affect the other. Lastly, if you look closely at the note portion, you'll see I put R's instead of 2. R just stands for rest, and it acts like any other note (except that it's silence). Thus, instead of holding the notes for a half note (the 2), I play a quarter note and then a quarter rest (which adds up to the same as a half note).

And that's all I have for the "Basics of MML". I'll post another time with the more advanced stuff, like shaping notes and other effects. Using just the stuff you've hopefully learned by now, you should be able to make some nice melodies. If you want to continue without me, you can look at the first link I posted to see every single MML command available. Just start throwing stuff into the "Mary Had A Little Lamb" song and see what happens!

Edited on by randomous

randomous

AuthorMessage
Avatar

GraphicGenius

36. Posted:

Well,I'm new to petit computer and i learned how to use some commands and made a small program which was basically just a conversation that you have with a sprite. It had about 50 commands but I want to make much more. So from now on I will be posting things on here everyday. Please add my friend code too,I really need someone to help me with some things.

If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?

3DS Friend Code: 1478-3545-5136 | Nintendo Network ID: GreatGamer123

AuthorMessage
Avatar

GraphicGenius

37. Posted:

Well, this is about the INPUT command:
So one of the most useful commands to me is the INPUT command because it lets you be able to type something which can be used later. Let's say you use the input command to type in your name. You could make the variable NAME$ be the name of someone and use like this:
PRINT “hello ”NAME$
But remember that you can't put NAME$ in the quotation marks or it will end up like this:
hello NAME$
Now who would want that? Also a command used mostly for input called if (which means the exact same thing as the word) can make a limited amount of answers available. So if you were to print “do you like me ” then do input LIKE$ you would be able to do:
IF LIKE$==“YES” THEN GOTO @YES
You could also add this:
IF LIKE$==“NO” THEN END
Wow,that's a lot for just input. I still have so much to say,but I guess I'll end here.
See you later!

Edited on by GraphicGenius

If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?

3DS Friend Code: 1478-3545-5136 | Nintendo Network ID: GreatGamer123

AuthorMessage
Avatar

GraphicGenius

38. Posted:

Could someone please show me how to use GCIRCLE? I also want to know how to use the DATA command and you guys are the only ones who would probably listen to me.

If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?

3DS Friend Code: 1478-3545-5136 | Nintendo Network ID: GreatGamer123

AuthorMessage
Avatar

StickyNote

39. Posted:

OK, i need help.
How do you make a program that lets a SPRITE move with the d-pad (up, down, left, right) and make him NOT slow, just moderately fast. Like... Pokemon fast.... i guess :p

StickyNote

AuthorMessage
Avatar

Xtremetdifan

40. Posted:

No. Sonic Fast!

Pokemon Mains:Infernape,Stunfisk,Garchomp
Smash Mains:Sonic,Fox,Ike

3DS Friend Code: 4124-5259-4542