DIM is short for "dimension", and is used to create an array of the size you want. (An array is basically a variable with one name that can hold many different values.)
For example, if you were working on a program that would play a simple card game you might write code like the following:
DIM DECK(52);
FOR I=0 TO 51
DECK(I) = I+1
NEXT I
FOR J=0 TO 51
SWAP DECK(J), DECK(RND(52))
NEXT J
The first part would create an array the size of a deck of cards, and then gives unique values to each entry in the array. The second part "shuffles" the deck by swapping each array value with one other randomly selected array value.
Some important things to know about arrays and the DIM statement:
you can only use DIM once for each array, after that the array is permanently set at the specified size; trying to use DIM a second time with the same variable will cause your program to crash with an error
if you treat a variable like an array without using DIM, then Petit Computer acts like you used DIM arrayname(10) by default
So what is DATA all about? Well, the first thing to know is that you don't use DATA on it's own: you also need to understand the READ and RESTORE commands.
You may want to store information that doesn't change in your program Maybe this means map data, or music data, or any other kind of information that won't change. The RESTORE/READ/DATA commands come in really hand here! They let you separate all that non-changing information from the body of your coding. DATA statements don't do anything other than contain a list of comma-separated data values. They are often found at the very bottom of a program, sitting somewhere after the END statement. The real action takes place when READ is used - this command tells Petit Computer to return the next DATA value and store it in a variable, ready to be used for whatever purpose you want.
DIM SUIT$(4);
FOR I=0 TO 3
READ SUIT$(I)
NEXT I
END
DATA "Diamonds", "Hearts", "Clubs", "Spades"
One last note: if you are using READ/DATA commands, then you need to understand what value will be returned at what time. When you use READ, Petit Computer starts looking from the beginning of the program for the first DATA statement, and then takes the first value from that statement. Every time you use READ after that point in time, it just jumps to the next comma-separated value, and if there is no next value in that DATA statement it will jump to the next line that does have a DATA statement in your program. If you use READ and there are no DATA statements left to read from, an error occurs.
This brings up two interesting points: you might need to add a "dummy" value at the end of your DATA statement so you know when to stop reading, and you should understand that you can (at any time) use the RESTORE command to change where Petit Computer will look for the next DATA value.
@START
READ L$
IF L$=="-1" THEN RESTORE @LETTERS: READ L$
PRINT "Letter "; next_letter$
INPUT "Again"; q$
IF q$=="Y" GOTO @START
PRINT "Bye!"
END
DATA "a", "b", "c" @LETTERS
DATA "d", "e", "f", "-1"
Okay, thanks, I think that helped a little, but I keep seeing stuff like "FOR I=0 TO 51", what is that for?
Without trying to brush you off, if you don't understand how a FOR-NEXT statement works then you need to do some basic learning before asking questions.
Those are the best links I could find on short notice, although someone else might be able to point you to other online resources. Don't look for specific answers yet - just learn everything they talk about because you will need to know it all.
Post question when stuff doesn't make sense, but you'll need to make an effort to get started. The good news: it's worth the effort, and you'll be programming in no time if you take the time to walk through some of these tutorials!
Okay, thanks! I do know about some of the basics (Such as variables, printing, GOTO, etc.) and I have started learning about sprites, but I guess there is sill a lot more to go! I'll start reading all of this!
Edit: Oh, wait! I've actually used one of those tutorials before, and now some of the stuff I've forgotten is coming back to me!
Great start! Add in subroutines, IF-THEN conditions, and FOR-NEXT loops and you've got a pretty good background for simple programs.
Sprites and graphics are really a whole leap above that. Not that they are hard - Petit Computer makes it pretty easy to start working with sprites, actually - but there is another layer of learning involved and plenty of trial-and-error moments. I'm a complete novice in that regard.
Anybody thinking of a date simulater game? (Or prehaps a hibread game with date simulater aspects like Sakura Wars) That is one gendra of game I have yet seen in Petit Computer.
Wow suddenly after waiting 16 hours i finally got reply, thanks to everyone who commented on my question.
I didn't realize.. that the second dimension in the multidimensional array would start at 0 by default.. everything is offset by 1 >.< That makes it confusing.
That's usually why in these languages I Just cheat by making my arrays one size larger than they need to be, and when that didn't work I made it even bigger...
guess that I forgot to account for the second dimension of that array.. figures i guess o.0
I'm making an AI still and it's slowly coming along but I need help writing code which helps me to parse some input. I think I know where I went wrong now though with my last scripting thing.
@randomouscrap I'd be thrilled if you could manage to do a dkc gb mix remake thing.
Has anyone here played with fami tracker i'm finding it hard to use but I used to use it and I was ok with it. I found more out about it today then ever before..
I'm thinking of doing some 8 bit chiptune related stuff.. unfortunately it doesn't have an option to export to MML I don't think.
Are there any trackers that can export to MML?
who here wants to help with my lttp thing?
I'm sorry that I haven't still looked at Coral Maze yet u_u I've been busy. But I'll take a look at it today. I'm really good at programming logic so it shouldn't take me more than a few minutes to figure out how it works, and then I can spend a few hours adding to it yay! ^^;
Got a project? PM ME on here!
Youtube: lostkitty64x
Want help with coding? PM ME! PM ME PM ME!! XD
FC: WIll post later.
Systems I own: ds lite, 3DS, PC/gaming, steam platform. I play alot of games. Just ask ! Minecraft anyone? :D
Okay, thanks, I think that helped a little, but I keep seeing stuff like "FOR I=0 TO 51", what is that for?
Without trying to brush you off, if you don't understand how a FOR-NEXT statement works then you need to do some basic learning before asking questions.
Those are the best links I could find on short notice, although someone else might be able to point you to other online resources. Don't look for specific answers yet - just learn everything they talk about because you will need to know it all.
Post question when stuff doesn't make sense, but you'll need to make an effort to get started. The good news: it's worth the effort, and you'll be programming in no time if you take the time to walk through some of these tutorials!
Thank you for posting this! It is really helping me to learn BASIC!
I'm planning on making a program this summer that can solve differential equations by building onto my quadratic solver. I know that petit computer can't float very many numbers, but I thought that this would be a fun thing to do this summer. When it comes to math, I have finished Calculus and I have just finished a course on differential equations. If anybody here has an expertise in this area of programing/mathematics, then let me know. :]
I'm planning on making a program this summer that can solve differential equations by building onto my quadratic solver. I know that petit computer can't float very many numbers, but I thought that this would be a fun thing to do this summer. When it comes to math, I have finished Calculus and I have just finished a course on differential equations. If anybody here has an expertise in this area of programing/mathematics, then let me know. :]
I forgot to mention that the reason that I am going to build on my quadratic solver (which is on the qr sharing page) was so that I could use that program to find the roots of characteristic equations of certain DEs.
I'm planning on making a program this summer that can solve differential equations by building onto my quadratic solver. I know that petit computer can't float very many numbers, but I thought that this would be a fun thing to do this summer. When it comes to math, I have finished Calculus and I have just finished a course on differential equations. If anybody here has an expertise in this area of programing/mathematics, then let me know. :]
I forgot to mention that the reason that I am going to build on my quadratic solver (which is on the qr sharing page) was so that I could use that program to find the roots of characteristic equations of certain DEs.
Wow you're picking one project to do? I've got atleast 12 lined up o.o but not all for petit computer and I'm constantly in over my head with trying to learn stuff xD
Got a project? PM ME on here!
Youtube: lostkitty64x
Want help with coding? PM ME! PM ME PM ME!! XD
FC: WIll post later.
Systems I own: ds lite, 3DS, PC/gaming, steam platform. I play alot of games. Just ask ! Minecraft anyone? :D
@VincentFaraday You know, I was planning on making a graphing application myself. One of the things I need in order to make it work a little more nicely is a DE solver. If you manage to make it work, it would be really cool if I could use it for the grapher.
@VincentFaraday You know, I was planning on making a graphing application myself. One of the things I need in order to make it work a little more nicely is a DE solver. If you manage to make it work, it would be really cool if I could use it for the grapher.
Well, a DE solver won't help you graph anything, but it could save you some time when dealing with homogenous linear equations (which is what I want to work on first). I'm also interested making graphing software for petit computer, but as I am sure you know petit computer can't handle it when x>10^6 (I found this out when I wrote a program that could calculate factorials and the program crashed at 10!) and that it can't float very many numbers. In spite of all this it is possible to create a semi-decent graphing program. I thinks it's great that there is someone else out there that is working on math applications for this software.
@VincentFaraday I was going to use the DE solver to calculate min/maxes for equations. What I want to be able to do is analyze an equation and try to best determine an appropriate range for it. Otherwise, the user would have to set a range for each equation. For instance, if I have:
y=sin(X)
VS:
y=17sin(x)
One of those is going to look ugly if the same range is used for both.
@VincentFaraday I was going to use the DE solver to calculate min/maxes for equations. What I want to be able to do is analyze an equation and try to best determine an appropriate range for it. Otherwise, the user would have to set a range for each equation. For instance, if I have:
y=sin(X)
VS:
y=17sin(x)
One of those is going to look ugly if the same range is used for both.
Oh, I understand. You are planning on using the first derivative test to find max /min. Yeah, I can see how you would want a program that can calculate derivatives. If I can write a program that is fairly good at finding dy/dx I'd be glad to share it with you.
Forums
Topic: Petit Computer
Posts 2,501 to 2,520 of 9,620
Please login or sign up to reply to this topic