Forums

Topic: Petit Computer Tutorials

Posts 21 to 40 of 101

Linput

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 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! :)

Linput

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! :)

Linput

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! :)

heatguts

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 by heatguts]

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

IAmSpike

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 by IAmSpike]

Previously Philip.

The most paranoid person on the net!

Linput

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! :)

ZombieChiggers

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

-Angel-

[Edited by -Angel-]

-Angel-

ChangeV

ChangeV

randomous

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 by randomous]

randomous

randomous

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

GraphicGenius

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?

thecrow

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

randomous

[Edited by randomous]

randomous

GraphicGenius

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?

GraphicGenius

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 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?

GraphicGenius

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?

StickyNote

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

StickyNote

Arn0ld

No. Sonic Fast!

Botw > OoT

Please login or sign up to reply to this topic