The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
Please vote in the Forum Structure Poll. Polling will close at 2PM EST on January 21, 2025.

Petit Computer - program BASIC games and apps on your DSi/3DS, out now on NA DSiware

UncleSporkyUncleSporky Registered User regular
edited July 2012 in Games and Technology
http://www.youtube.com/watch?v=4AYlEo3rJHs

Petit Computer is DSiware that allows you to program cool things for your DSi, DSiXL or 3DS using the BASIC programming language. The program seems designed for simple game development, including a variety of commands for working with sprites and backgrounds, but you could theoretically program any number of useful apps.

It includes some sample graphics, music and sounds, and also editors to create your own. You can save your creations to the SD card, connect it to your computer, and generate QR codes to share it with others. I believe you can also just share the file, but QR means others don't have to futz with SD cards. :)

We're getting it in America on July 19 for $8. This thread's a bit premature I admit, but it's never too early to start learning to program and getting acquainted with what you can do. The program's website includes a samples page with code for all of the included programs. As an example, here's the first demo program:
    '+------------------------+
    '|        SAMPLE1         |
    '|   Output characters    |
    '|       to console       |
    '+------------------------+
    VISIBLE 1,1,0,0,0,0
    CLS:COLOR 0
    '--- Character display
    PRINT"Ж:NICO Mark"
    PRINT"ALPHABET"
    PRINT"12345";"KATAKANA"
    '--- Assign color
    COLOR 12:PRINT"а";
    COLOR 13:PRINT"б";
    COLOR 11:PRINT"Я";
    COLOR 9:PRINT"в"
    COLOR 0
    '--- Use variable
    APPLE=56
    ORANGE=123
    '--- Assign display location
    LOCATE 5,10
    PRINT"Apples = ";APPLE;"
    LOCATE 5,11
    PRINT"Oranges = ";ORANGE;"
    LOCATE 5,12
    PRINT"-----------"
    LOCATE 5,13
    TOTAL=APPLE+ORANGE
    PRINT"Total = ";TOTAL
    '--- end
    PRINT ""
    PRINT "─"*32;
    PRINT "PUSH А"
    @KLOOP
    VSYNC 1
    IF BTRIG()!=16 THEN @KLOOP
    END

We are getting version 2 of the software which included many improvements such as the ability to share your programs (users used to upload video of their source code!). This program's been around in Japan for a while, and I never expected it to be localized. I'm pretty excited for it!

In Japan it's known as Puchicon for short. You can click that link to see a search of Youtube for the term, which shows a lot of programs that have already been made. Here are some noteworthy examples:

A port of Outrun

Spectacle Hurricane, a Space Harrier clone

Super TryGunners, a space shooter

A port of Genesis's Columns

An introductory animation from Ys 3, showing off smooth scrolling

The Japanese version included speech synthesis for generating Japanese speech, which is not included in our version. There were a couple sample programs teaching how to use it which are conspicuously absent from the english sample page.

The software includes 8 banks of sprites like this one:

Zidh1.gif

4 banks of backgrounds like this one:

PPYTb.gif

30 built-in songs and 70 sound effects, with 128 instrument MIDI and custom waveforms.

Here are some of the program's specifications:

- Programs with names of up to 8 characters, supporting 9999 lines of code, though you can launch other programs from within your program and include additional program data. I'm not sure whether program size is virtually unlimited because of this or if there are other caveats.

- Strings and numeric variables with names of up to 16 characters. Integers must be in the range of ± 524,287.

- Arrays of up to two dimensions, with up to 262,144 individual elements. String arrays must contain fewer elements, I believe.

- During program execution, the use of every DSi button other than select, which is used to return to the console screen. You can also use the touch screen for conventional touch coordinates or virtual keyboard input.

- 100 simultaneous sprites, which can be sized in almost any combination from 8x8 pixels to 64x64.* They can be used for characters, enemies, bullets, particles, any number of things. Sprites are optimized for ease of movement, animation, rotation, scaling, and collision detection. There are built-in commands for all of these that will vastly help streamline game creation.

* no 8x64, 16x64, 64x8, or 64x16.

- Multiple drawing layers, as follows:
  • At the back, a default background color.
  • A drawing plane where you can output manually-drawn images of lines, filled shapes etc. If I'm reading the specs correctly, this plane contains two pages per DSi screen that you can flip between in order to create smooth animations, i.e. you can draw to the offscreen page and display it when ready.
  • Two graphics planes used for BG tiles. While DSi's screens are 256x192, these planes are 512x512 and can be offset from their default position to scroll the image around. They also support transparency for layering purposes; as an example, see the BG bank above. You'd draw the stump on the lower layer and the tree's leaves on the second. You can also use them for parallax scrolling, mountains in the far background etc.
  • At the front, the console display on the top screen and keyboard on the bottom screen. The console supports 32x24 characters and can be used for simple text programs or very basic games. These planes can be hidden to work with only the graphical planes below.
  • Individual sprites can be positioned between any of the above planes.

That is probably enough for an OP.

There is a third party editor that allows you to edit all aspects of your programs via PC and convert back to the DSi format, saving you tons of mental anguish from typing on DSi's touch screen. I will post about that in a bit.

Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
UncleSporky on
«1

Posts

  • PolaritiePolaritie Sleepy Registered User regular
    edited July 2012
    Hmm... Not really BASIC if it does all that.

    Frankly, with all those extra features, they should have used an OO language.

    Polaritie on
    Steam: Polaritie
    3DS: 0473-8507-2652
    Switch: SW-5185-4991-5118
    PSN: AbEntropy
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    Yeah, it's probably the programmer in me, but BASIC seems like a terrible programming language for this. It's really not any easier to learn than something like Ruby, and its going to frustrate any semi-experienced developers that use it.

    That said, this is still very cool. I expect to see more and more games like this, as time goes on. With Notch's assembly emulator in his next game, and now this, I hope this becomes a trend.

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • PolaritiePolaritie Sleepy Registered User regular
    Hell, even C would be far better, at least it uses normal syntax.

    Steam: Polaritie
    3DS: 0473-8507-2652
    Switch: SW-5185-4991-5118
    PSN: AbEntropy
  • UncleSporkyUncleSporky Registered User regular
    edited July 2012
    I think Japan has an affinity for BASIC, though admittedly I don't have much perspective on that subject. I do know that many of their early popular computers supported it, and the Famicom (NES) in Japan even had a version of it. This could be an extension of that, the nostalgia of something that got enthusiasts into programming years ago and could do the same for a new generation of programmers.

    There have been a number of improvements to it here that make it a little more user friendly - for example, while it still uses line numbers, I believe you can insert new lines wherever you want and it re-numbers the rest of the program, and "goto" uses @labels instead of line numbers. It's also got a number of syntax changes to bring it in line with other languages, for example, using != instead of <>.

    Anyway.

    So somebody elsewhere linked a port someone in Japan made of the old Star Trek BASIC game. He mentions a javascript-generated QR code of the source, which meant that there must be some way to edit Petit Computer's files on a PC. Since his Star Trek page was in decent english, I decided to drop him a line and asked whether PC editing was possible. He told me it was, and provided a link to this program:

    PTCUtilities, a full suite for editing Petit Computer programs

    LMp8V.jpg
    kumQP.jpg

    An english version is in progress. You can download it now and it's mostly there already.

    This will make creating programs for DSi much easier. You can import graphics from any source and generate palettes and graphic banks. You can search for text in your program and jump between labels. And most importantly, you can type on an actual keyboard. :P

    So it's nice to have a good utility like this available even before day one of release.

    UncleSporky on
    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • UncleSporkyUncleSporky Registered User regular
    edited July 2012
    This is out today!

    Here's the manual run through Google Translate. You may need to manually change the "p02" at the top to other page numbers (p03, p04 etc.) if the page links aren't working. And here is a cool single page command reference (also run through Google Translate).

    Smileboom has been posting free graphic sets you can use for your own games. The ones they've given out recently are for people who want to make their own Advance Wars! QR codes at the links, including palettes:

    http://smileboom.com/special/ptcm2/co_present/html_present03.php

    EUWpE.png
    8RPIU.png

    http://smileboom.com/special/ptcm2/co_present/html_present04.php

    Q8sxV.png
    MTIwZ.png
    Ybq6F.png
    nAdmX.png

    Other stuff:

    Here is an amazing massive music synthesizer someone made. Seriously it's ~60 QR codes long. Looks like professional software you might pay for (video).

    mfTbr.jpg

    A post from GAF:
    Wiggler wrote: »
    Some links to QR codes that I compiled (and confirmed working):

    Games
    - Jumping Island
    - Convee (keep the ball alive by moving up and down)
    - Super Monster (video)
    - Tama (roll a marble on your touch screen to get an odd number in order to progress to the next level)
    - Hayabusa (satellite simulator)

    Apps
    - Drawing Tool (QR codes at 3:50)

    A friggin' raytracer someone made.

    Actually here's the Japanese wiki where people have posted all sorts of programs.

    UncleSporky on
    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • Xenogears of BoreXenogears of Bore Registered User regular
    BASIC's syntax is pretty easy to learn and should be familiar to any programmer in his late 20's or beyond as most formal education in computer programming began with BASIC back in the day.

    I love me some basic. If I find the code I wrote for a Pokémon clone back in the late 90's on my old hard drive I'll try and bring it out for all to see.

    3DS CODE: 3093-7068-3576
  • DarmakDarmak RAGE vympyvvhyc vyctyvyRegistered User regular
    The game Evochron Mercenary was made in Dark Basic by one dude if I remember correctly. I don't know shit about programming and don't know how different that is from regular basic, but this thread made me think of it.

    JtgVX0H.png
  • Warlock82Warlock82 Never pet a burning dog Registered User regular
    edited July 2012
    BASIC's syntax is pretty easy to learn and should be familiar to any programmer in his late 20's or beyond as most formal education in computer programming began with BASIC back in the day.

    I love me some basic. If I find the code I wrote for a Pokémon clone back in the late 90's on my old hard drive I'll try and bring it out for all to see.

    I started in C++ :P Honestly I've never really coded in BASIC, though I can't see it being *that* hard (albeit cumbersome I'd imagine)


    As for the comment about coding on a PC, that would be quite nice. To be honest, I'd rather not try to type with a stylus if I can avoid it :D Looks like the program is in Japanese though which is a shame. I hope someone translates it (not that I'm sure it wouldn't be that hard to figure out, but still...)

    Warlock82 on
    Switch: 2143-7130-1359 | 3DS: 4983-4927-6699 | Steam: warlock82 | PSN: Warlock2282
  • ZxerolZxerol for the smaller pieces, my shovel wouldn't do so i took off my boot and used my shoeRegistered User regular
    edited July 2012
    Darmak wrote: »
    The game Evochron Mercenary was made in Dark Basic by one dude if I remember correctly. I don't know shit about programming and don't know how different that is from regular basic, but this thread made me think of it.

    There's so many permutations of BASIC that any one implementation can be quite different from another, from very modern variants like Visual Basic all the way back to very primitive dialects. This thing looks more similar to the old school, programming-on-a-70s-microcomputer versions.

    Line numbers man. Nostalgia'd up.

    Zxerol on
  • UncleSporkyUncleSporky Registered User regular
    edited July 2012
    Warlock82 wrote: »
    As for the comment about coding on a PC, that would be quite nice. To be honest, I'd rather not try to type with a stylus if I can avoid it :D Looks like the program is in Japanese though which is a shame. I hope someone translates it (not that I'm sure it wouldn't be that hard to figure out, but still...)

    Did you download it? It's actually already mostly in english, and he's improving it regularly. I have no trouble understanding how to use it.

    All you really need to start with is the PRG editor. Type some BASIC code, generate a QR code from it, read it with your DS.

    UncleSporky on
    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • Warlock82Warlock82 Never pet a burning dog Registered User regular
    edited July 2012
    Not yet, I'll mess with it later. Was just looking at the screenshots which showed mostly Japanese.

    I did download the Star Trek game though, that's really well done! I honestly don't know how to really *play* it (though I actually did use to have that way back when), but the interface and everything are nice. Even if they do spell Klingons "Kilins" (or something stupid like that). I'm tempted to go into the code and fix the numerous spelling errors and typos :D

    The "other version" they link to somewhere on that page sucks though. "Type 1-5" and you are just supposed to know what those refer to :P (ex: 1 = warp, etc)

    The synthesizer was also cool (took freaking forever to download) but I don't really know how to use it. Other than hitting random buttons and ruining the sound quality :P

    Edit: Holy crap!
    http://translate.google.com/translate?sl=auto&amp;tl=en&amp;js=n&amp;prev=_t&amp;hl=en&amp;ie=UTF-8&amp;layout=2&amp;eotf=1&amp;u=http://wiki.hosiken.jp/petc/?Toukou&amp;act=url

    Someone made a rudimentary version of Scorched Earth (or whatever game Scorched Earth ripped off, which in turn was ripped off by Worms)

    Warlock82 on
    Switch: 2143-7130-1359 | 3DS: 4983-4927-6699 | Steam: warlock82 | PSN: Warlock2282
  • UncleSporkyUncleSporky Registered User regular
    edited July 2012
    Warlock82 wrote: »
    I did download the Star Trek game though, that's really well done! I honestly don't know how to really *play* it (though I actually did use to have that way back when), but the interface and everything are nice. Even if they do spell Klingons "Kilins" (or something stupid like that). I'm tempted to go into the code and fix the numerous spelling errors and typos :D

    He said he did that on purpose to avoid copyright issues or something.

    Some of the built in programs have weird translation issues though. I was in the CHR editor and went to load a new palette and it asked me if I wanted to load the splite palette! And when you try to run away in the dungeon game, you'll either "not got escape" or "get escape." :P

    UncleSporky on
    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • agoajagoaj Top Tier One FearRegistered User regular
    I wish this was a 3DS app for the large screen and more memory
    but I bought it anyways.

    ujav5b9gwj1s.png
  • agoajagoaj Top Tier One FearRegistered User regular
    edited July 2012
    Hmm, anyone know how to create string arrays?
    Anyways I made a little sound test program to try out all the sounds and bgm included with petit computer.
    ZEHsE.png

    Edit:
    Ok, now I've made something to draw 3D triangles
    HF8mC.png
    Starts having issues at about 8 triangles, might be able to improve it by clipping the lines smarter. Pretty cool to fly around though.
    Up-Down to move in and out, Left Right to pan left right, and L and R to pan up and down

    agoaj on
    ujav5b9gwj1s.png
  • ejamerejamer Registered User regular
    edited July 2012
    agoaj wrote: »
    Hmm, anyone know how to create string arrays?
    ...

    Same as for numbers, just use "$" at the end of the array name. (And sort works just fine, in case you were wondering.)

    DIM ArrayName$(ArraySize)
    FOR i=0 TO ArraySize-1
    ArrayName$(i) = "string"+STR$(ArraySize-i)
    NEXT

    ejamer on
  • DonnictonDonnicton Registered User regular
    edited July 2012
    Freakin' yes.

    http://www.youtube.com/watch?v=be1Z0GjsA1Y


    Also, Ys Book I + II intro this time (what makes this especially noteworthy is halfway through the video)

    http://www.youtube.com/watch?v=ARi5C_0dTV4

    Donnicton on
  • agoajagoaj Top Tier One FearRegistered User regular
    The TALK command has been disabled in the english version, something about licensing.

    ujav5b9gwj1s.png
  • Warlock82Warlock82 Never pet a burning dog Registered User regular
    Man, I would love to see the QR codes for that Ys cutscene :P Must be 200+ of them :)

    Side note, that little Star Trek game is a lot of fun. I really wish he'd have laid the buttons out logically though. He should have just made the keypad match the directions that the numbers refer to. I had to mentally keep track of it which is pretty annoying.

    Switch: 2143-7130-1359 | 3DS: 4983-4927-6699 | Steam: warlock82 | PSN: Warlock2282
  • ejamerejamer Registered User regular
    edited July 2012
    It's not hard to edit the program yourself, but fixing the numbers is a bit more complex than changing the text back to Enterprise/Klingons. Try searching for the variable c1 if you are interested in making an adjustment about course entry yourself. I hacked on a quick subroutine that adjusts the value whenever c1 is set, and it works just fine. You also might want to see how the title is displayed, as it's easy to restore the "real name" on the title screen since the relevant DATA statements were all still in place and just needed to be uncommented.

    ejamer on
  • Warlock82Warlock82 Never pet a burning dog Registered User regular
    BTW, is there an easy way to bring up the source code of programs? The only way I've found is with that annoying 'LOAD "<programname>" command which requires you to remember the name :(

    Switch: 2143-7130-1359 | 3DS: 4983-4927-6699 | Steam: warlock82 | PSN: Warlock2282
  • ejamerejamer Registered User regular
    LOAD is the only way I know how to see code. But you can use the FILES command to see a list of available resources to load instead of having to try and remember everything.

  • UncleSporkyUncleSporky Registered User regular
    edited July 2012
    Alright, here's my first major test program.

    I wanted to start with a nice big map to scroll around, but who wants to bother making their own? I looked up Dragon Quest's map data (which is simple RLE compressed), wrote a program to convert the raw binary to a series of DATA statements, wrote a decompression routine, discovered some really weird quirks, modified the data a bit, and finally ended up with this.

    http://i.imgur.com/ROcaM.png

    As the pic says, it displays part of the DQ1 map that you can scroll around while listening to the town theme. It's awkward right now since I'm just drawing a chunk to the 512x512 background and not touching it again, so it cuts off abruptly and repeats in every direction.

    The next step is modifying it so that it scrolls properly, which is more complicated. Every tick of the CPU, you check what direction you're moving in and draw the next row or column of tiles if necessary. Not sure if Petit Computer is fast enough to do this well, but we'll see.

    Some points of interest:

    30,30 - the start of the game, Tantagel Castle, etc.
    0,0 - Garinham
    91,60 - Rimuldar
    60,85 - Cantlin

    Let me know what you think!

    UncleSporky on
    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • UncleSporkyUncleSporky Registered User regular
    edited July 2012
    Ok, here it is, basically the full version of the above:

    http://i.imgur.com/xMF8m.png

    You can scroll around the whole Dragon Quest 1 map smoothly. Diagonals are a little jittery because Petit Computer is not fast enough to draw both a horizontal and vertical row of tiles in the same frame. It wouldn't be a problem if I split up the horizontal/vertical drawing between two frames but this is just a demo. :)

    As it says on the pic, the program draws new tiles just off screen when it needs to scroll in that direction. If you're moving to the right, it draws the next column to the right. If you're moving downward, it draws the next row downward. When drawing columns it actually draws one extra tile on the top and bottom so it takes care of the corner tile when moving diagonally.

    Took a lot of messing around but it's satisfying to have it working. I know it's not impressive on the surface, games are expected to be able to do things like this, but that's why routines like this are necessary. I could add some more user-defined variables and make it very adaptable for any type of map array, usable in platformers etc. Of course it'd still be pretty complicated to use.

    UncleSporky on
    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • agoajagoaj Top Tier One FearRegistered User regular
    Nice, I'm working on a wolfenstein style raycaster. So far it's running at 2 frames per second for full screen mode.

    ujav5b9gwj1s.png
  • UncleSporkyUncleSporky Registered User regular
    I made a text adventure engine (choose-your-own-adventure style, no typing). Hopefully it will be helpful to new programmers who want to make something fun to share with others. There a sample "adventure" included to help show off how it works. It's extensively commented to explain as much as I could about how to use it.

    http://i.imgur.com/vjzfq.png

    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • XaviarXaviar Registered User regular
    Ha. This is awesome, I'll have to download this!

  • Warlock82Warlock82 Never pet a burning dog Registered User regular
    Ok, here it is, basically the full version of the above:

    http://i.imgur.com/xMF8m.png

    You can scroll around the whole Dragon Quest 1 map smoothly. Diagonals are a little jittery because Petit Computer is not fast enough to draw both a horizontal and vertical row of tiles in the same frame. It wouldn't be a problem if I split up the horizontal/vertical drawing between two frames but this is just a demo. :)

    As it says on the pic, the program draws new tiles just off screen when it needs to scroll in that direction. If you're moving to the right, it draws the next column to the right. If you're moving downward, it draws the next row downward. When drawing columns it actually draws one extra tile on the top and bottom so it takes care of the corner tile when moving diagonally.

    Took a lot of messing around but it's satisfying to have it working. I know it's not impressive on the surface, games are expected to be able to do things like this, but that's why routines like this are necessary. I could add some more user-defined variables and make it very adaptable for any type of map array, usable in platformers etc. Of course it'd still be pretty complicated to use.

    Wow, impressive! I still need to figure out how to code anything on here :P heh... Shame it's not some form of C, it'd be a lot easier to read the examples' source code (although yours has probably made more sense than anything else I've looked at).

    Switch: 2143-7130-1359 | 3DS: 4983-4927-6699 | Steam: warlock82 | PSN: Warlock2282
  • agoajagoaj Top Tier One FearRegistered User regular
    BTW, don't goto out of a for loop. Petit Computer considers you still in the loop when you do that. You'll see strange behavior with nested loops, and eventually a stack crash with non-nested loops.
    NEXT takes a variable as an argument, but I can't just give it 10000 to end the loop so I'm not sure what options that opens up. So do I=agazillion : NEXT : GOTO when you need to jump out of a loop.

    ujav5b9gwj1s.png
  • UncleSporkyUncleSporky Registered User regular
    I have no qualms about

    X=0
    @LOOP
    X=X+1
    'do stuff including jumping out with GOTO if necessary
    IF X<1000 GOTO @LOOP

    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • TayaTaya Registered User regular
    Anybody know of any simple games and programs that I could copy for the purposes of tutorials? I've done the two or three on GameFAQs including UnlceSporky's Move a Ball game. The stickied topic over there is an example of a great tutorial because it explains everything well, but it's a little too simple.

  • UncleSporkyUncleSporky Registered User regular
    Did you try my choose-your-own-adventure above? I commented it as well as I could to explain how it works. If you have other questions I can answer them.

    Or if you want to do more advanced things like use sprites and the background I can help with that too. I would rather make stuff that is fun to me rather than making tutorial programs all the time, but just explaining how stuff works isn't too hard. Sprites and background are actually pretty easy.

    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • TayaTaya Registered User regular
    I've looked at your adventure game and it's pretty useful. Tutorials that walk you through each step is useful for describing commands that I wouldn't think to use. I still don't get DATA and how to use the bottom screen, let alone the more complex commands. I figured out sprites but it took a solid hour of experimenting.

    I'm not asking you to make a tutorial; I'm wondering if tutorials exist. There are some in Japanese on the official website although I don't know if they explain anything complicated.

  • agoajagoaj Top Tier One FearRegistered User regular
    edited July 2012
    DATA is used in place of having a separate data file.

    So you have
    @myFirstLabel
    DATA "Growbalow", 20
    @mySecondLabel 
    DATA -1.23
    /*BUNCH OF CODE*\
    DATA "adios amigo"
    

    Imagine that all the DATA statements are removed and put in their own file. Your program doesn't have to reach a DATA statement for it to do anything, you can put DATA anywhere in your program.
    You can then use the READ command to read it.
    READ x$, y, z
    
    this reads from the first DATA statement, and onto the second and third because we put in three variables, and loads that data into those variables. so x$ is now "Growbalow", y is 20, and z is -1.23.
    if we do another READ to a string variable, we'll get "adios amigo", as this is the last DATA statement, any more reads will cause the program to crash. If you're using DATA statements where you don't know how many there are, you'll want to have something at the bottom that you can check so that you know you're at the end, of either the program or just the section of DATA you want to read.

    To get more out of READ, you'll want to use RESTORE.
    RESTORE changes what DATA statement you'll read from. so RESTORE @mySecondLabel and then READ would get you -1.23, or we could go all the way back to the beginning with RESTORE @myFirstLabel. It uses the exact same labels that goto and gosub use, but relative to the DATA statements.
    This is useful if you want to have one print function to throw up a full screen's worth of text.
    @intro
    DATA "A long time ago", "Bad Stuff", "END"
    @outro
    DATA "Good stuff!", "END"
    RESTORE @intro
    GOSUB @myPrinter
    

    agoaj on
    ujav5b9gwj1s.png
  • 81Rambler81Rambler Registered User new member
    I was wondering if I could get some help in the use of Arrays. I understand them to be similar (in function) to an in program spread sheet, however I havn't been able to get them to work properly dispite referencing other programs where they are used.

    The simpliest code I've attempted to use is this...

    DIM CARD(2,2)
    CARD(0,0)=1
    CARD(0,1)=2
    CARD(1,0)=3
    CARD(1,1)=4
    PRINT CARD (0,0)
    PRINT CARD (0,0)
    PRINT CARD (0,0)
    PRINT CARD (0,0)

    I realise I'm treating the array as a typical varitable, and maybe that is my problem, however in even attempting to use this code I get an error on the DIM line saying "Duplicate Definition". Am I misunderstanding the proper function of arrays entirely or is there something I'm missing?

    Also in use of arrays (if I havn't fudged things up already), would I be able to use both numerics and strings within the same array set?

  • agoajagoaj Top Tier One FearRegistered User regular
    edited August 2012
    The problem is that arrays can only be declared once, unlike other variable which can be redefined. When you restart your program, CARD is still defined as a 2 by 2 array.
    You need to start your program with CLEAR, that will erase all arrays, reset variables to 0 etc.

    Yes, you can mix strings and numbers, just reference the array like CARD$(0,0) to store/read strings.

    agoaj on
    ujav5b9gwj1s.png
  • 81Rambler81Rambler Registered User new member
    In that case, how do I go about putting data into specific areas of an array? Assuming I'm looking to say assign a list of a standard deck of playing cards to an array, I would probably have to assign several values at different times (number/face of the card, suit, etc). I assumed that the DIM command was what set the size of the array, which I could then write to specific 'cells' of an array as I would a varitable in other, seperate commands.

  • agoajagoaj Top Tier One FearRegistered User regular
    Yeah, array elements can by strings or numbers, but not other arrays.
    For cards there is some binary trickery you could do where the four suits are 16,32,64,128. Add the suit number to the card number(0-12 for ace-king) and store it in the array. Then you can test the suit with suit AND card, grab just the number with 15 AND card.

    For a more flexible approach, you could have each card take up multiple array slots. So if a card has 3 attributes(number,face,suit) you would have each card in the array take up 3 slots.
    cardsCount = 52
    dim card(cardsCount)
    for i=0 to cardsCount-1 'BASIC will run the loop with the number here, so when dealing with arrays you have to subtract one from the size. a 52 card array has elements 0-51
    card(i*3) = number
    card(i*3 + 1) = face
    card(i*3) + 2 = suit
    next
    

    ujav5b9gwj1s.png
  • UncleSporkyUncleSporky Registered User regular
    edited August 2012
    Taya wrote: »
    I've looked at your adventure game and it's pretty useful. Tutorials that walk you through each step is useful for describing commands that I wouldn't think to use. I still don't get DATA and how to use the bottom screen, let alone the more complex commands. I figured out sprites but it took a solid hour of experimenting.

    I'm not asking you to make a tutorial; I'm wondering if tutorials exist. There are some in Japanese on the official website although I don't know if they explain anything complicated.

    I don't think tutorials exist for this program. Tutorials exist for BASIC, but there are enough little differences that it would probably be frustrating.

    But yeah, DATA is just to store stuff inside your program. Think about ways you might do that. One way would be this:

    A=10 : B=10 : C=5 : D=10 : E=20 : F=20 : G=10

    (Colons are like putting code on a new line, so imagine that all stretched out vertically)

    Or if you did it in a single array, like this, which isn't really any better:

    A(0)=10 : A(1)=10 : A(2)=5 : A(3)=10 : A(4)=20 : A(5)=20 : A(6)=10

    That's really cumbersome and possibly annoying to find the part you need to modify later. It's not well organized and not something you can loop through automatically. So instead, we have DATA which is very helpful for assigning numbers and strings into variables easily.

    RESTORE @DATALOCATION

    FOR X=0 to 6
    READ A(X)
    NEXT

    @DATALOCATION

    DATA 10,10,5,10,20,20,10

    READ A(X) means A(X)=<next sequential thing stored in DATA>. Every time you use READ, it reads the next piece of data from wherever it left off, unless you've changed the read location with RESTORE.

    You can use it for all sorts of things. In my program, they're a set of text strings to be printed based on the page you're on. You can use it to make built-in maps out of a series of numbers. You can use it to keep small tables of information like what frames of animation should play with what timing - maybe the character is skipping along so you want to display frames 1,1,1,2,3,3,3,4.
    81Rambler wrote: »
    In that case, how do I go about putting data into specific areas of an array? Assuming I'm looking to say assign a list of a standard deck of playing cards to an array, I would probably have to assign several values at different times (number/face of the card, suit, etc). I assumed that the DIM command was what set the size of the array, which I could then write to specific 'cells' of an array as I would a varitable in other, seperate commands.

    You're doing it exactly right. It's just a matrix, or a 2x2 spreadsheet of cells. DIM is what sets up the size, and as you figured out it starts with 0 and will end one less than the DIM. And referencing a part of an array is literally the same as any other variable. If you type PRINT AWESOME or PRINT AMAZING(36,54), it's all the same sort of thing.

    I'm not sure why you'd store cards in an array, it doesn't seem all that useful. It's more useful for a collection of things that are similar but need to be recorded separately. So in an RPG, a monster has a type (bat, goblin), HP, MP, status effects, maybe X and Y on the screen if it's an action RPG, etc. And you'll have a maximum of 10 enemies or something. ENEMY(0,0) is the type of the first enemy, ENEMY(1,0) is the type of the second enemy, and so on. ENEMY(15,1) is the remaining HP of the 16th enemy.

    UncleSporky on
    Switch Friend Code: SW - 5443 - 2358 - 9118 || 3DS Friend Code: 0989 - 1731 - 9504 || NNID: unclesporky
  • 81Rambler81Rambler Registered User new member
    edited August 2012
    81Rambler wrote: »
    In that case, how do I go about putting data into specific areas of an array? Assuming I'm looking to say assign a list of a standard deck of playing cards to an array, I would probably have to assign several values at different times (number/face of the card, suit, etc). I assumed that the DIM command was what set the size of the array, which I could then write to specific 'cells' of an array as I would a varitable in other, seperate commands.

    You're doing it exactly right. It's just a matrix, or a 2x2 spreadsheet of cells. DIM is what sets up the size, and as you figured out it starts with 0 and will end one less than the DIM. And referencing a part of an array is literally the same as any other variable. If you type PRINT AWESOME or PRINT AMAZING(36,54), it's all the same sort of thing.

    I'm not sure why you'd store cards in an array, it doesn't seem all that useful. It's more useful for a collection of things that are similar but need to be recorded separately. So in an RPG, a monster has a type (bat, goblin), HP, MP, status effects, maybe X and Y on the screen if it's an action RPG, etc. And you'll have a maximum of 10 enemies or something. ENEMY(0,0) is the type of the first enemy, ENEMY(1,0) is the type of the second enemy, and so on. ENEMY(15,1) is the remaining HP of the 16th enemy.

    Well I will admit that relying on arrays for something that can be mathmatically simple as playing cards is a bit unnessesary I have a few reasons for doing this. Primarily to get my feet wet using arrays, but also I plan on making a bulk card engine that I can use to simplify not only the simple Black Jack game I plan on starting with, but something I could use down the road to simplfy getting information on each card for say a game of Solitare or Poker. So instead of having to DECK(Card)%4 in each command where I need to find it's suit I can just refer to DECK(Card,4) (4 being the row in the array where I dicate the suit).

    That said, I am having a few issues with the preiminary deck building array I have now. Here's the coding I have in place so far

    CLEAR:CLS:DIM DECK(52,5):CARD=0
    FOR CARD=0 TO 51
    IF CARD<=36 THEN DECK(CARD,0)=FLOOR(CARD/4)+2:DECK(CARD,4)=DECK(CARD,0)
    IF CARD>=35 AND CARD<=40 THEN DECK$(CARD,0)="J"
    IF CARD>=39 AND CARD<=44 THEN DECK$(CARD,0)="Q"
    IF CARD>=43 AND CARD<=48 THEN DECK$(CARD,0)="K"
    IF CARD>=47 THEN DECK$(CARD,0)="A":DECK(CARD,4)=1
    IF CARD>=35 AND CARD<=48 THEN DECK(CARD,4)=10
    DECK(CARD,1)=CARD%4
    DECK(CARD,3)=CARD%2
    NEXT
    --
    It's what I have so far. For the sake of mentioning 0 is kept for the printed card face, 1 for a numerical suit reference, 2 will be the printed suit (not implimented in this code yet), 3 the suit color (again for the sake of easier reference instead of mathmatically searching it every time) and 4 is currently used for it's value in a BlackJack hand (I'll be putting in-hand code to determain the differences between 1 and 11 for Aces). Further numbers will be used for other game specific values like proper card order in Solitare or Poker). Currently I'm building the deck starting with 2, following through the four suits, going to 3 and repeating until the aces at the end of the line.

    I'm currently running into an error in the 4th line 'Subscript out of range'. I checked the coding and while I seem to have a mild overflow for the IF/THEN statement (in that it seems to convert more cards then I intend to), but the error seems to stem from the DECK$ declaration. Do I need to alter this assignment for the sake of the "J" and other printed strings?

    EDIT - And just after posting this I realised I'll come into another stump down in road when I'm attempting to PRINT the results of column 0 and half of them are numerical and the other are strings. Attempting to change the numerics to strings however gives me the same error on that line as I did with the other, so I guess I know what my problem is. How should I go about putting these strings into the array?

    81Rambler on
  • eobeteobet 8-bit childhood SwedenRegistered User regular
    edited August 2012
    Holy shit... there really is a niche for these kinds of things still... amazing... maybe that 0x10c (spelling?) game Mojang are working on will work in Japan then...

    eobet on
    Heard the proposition that RIAA and MPAA should join forces and form "Music And Film Industry Association"?
Sign In or Register to comment.