Petit Computer Online Source
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Tutorial from a Box #2 Labels, Loops, and Input

3 posters

Go down

Tutorial from a Box #2 Labels, Loops, and Input Empty Tutorial from a Box #2 Labels, Loops, and Input

Post  boxtropica Wed Sep 19, 2012 5:24 pm

(EDIT: Sorry, I fixed the tutorial program now!)
Hello! Welcome back to Tutorials from a Box! For Tutorial #1 Click here

Ok, this time it's Labels, Loops, and Input!
First lets cover Labels!
Open up the editor and look at this:

@Source
PRINT "Hello"
goto @Source

Notice how there is no end to this- It is a LOOP!
Loops also use LABELS!

Let's examine the program:

@Source

That is a label. Labels start with @ and the name is after the @!
So @Source is named Source. "You may be asking what is the point of labels?"
Well, Labels are very useful! They set a location on the earth, or on the program.
So, goto @Source means to goto the label @Source!

@Source ""The Label
PRINT "Hello" ""Printing Hello
goto @Source "" Going back to @Source

So, do you get it?
If you go back to @Source, then you will always print Hello!
That is a loop! Also, it is the only way to do loops!
But Labels aren't only useful for loops, they are great for controls, menus, pretty
much anything you can think of!
So, just to make them a little more important; Lets throw in Input!

Oh, and "" in a program is a comment, which means anything after it on that line does not affect the program!


@Menu
cls
PRINT ">Play"
PRINT " Exit"
wait 8
goto @MenuCon

@MenuCon
b = button()
if (b and 16) goto @Play
if (b and 2) goto @MenuExit
goto @MenuCon

@Play
cls
PRINT "This is the Play Option!"
goto @Playender

@MenuExit
cls
PRINT " Play"
PRINT ">Exit"
wait 8
goto @MenuExitCon

@MenuExitCon
b = button()
if (b and 1) goto @Menu
if (b and 16) goto @Playender
goto @MenuExitCon

@Playender
end

Wow, that was pretty long.
But, it is a menu!
Lets take a look at the code:

@Menu ""The Label for the Play option
cls ""Clear the screen if someone selects it
PRINT ">Play" ""Show that the Play option is selected
PRINT " Exit" ""Show that the Exit option is NOT selected
wait 8 ""This is to wait- so it doesn't go SUUUPER fast!
goto @MenuCon ""Goto the controls for this part of the menu

@MenuCon ""Make the label that is the controls
button() = b ""This sets that the DSI/3DS button is b for short
if (b and 16) goto @Play ""16 is the A button, so when the play presses A it goes to the @Play label
if (b and 2) goto @MenuExit ""2 is Down, so when someone presses it it goes to the @MenuExit label
goto @MenuCon ""Loop, go back to @MenuCon

@Play ""This is the @Play Label, where the A button in @MenuCon goes to
cls ""Clears the screen
PRINT "This is the Play Option!" ""Show the player it is the Play option
wait 200 ""Wait 200 so the player can read that its the play option
goto @Playender ""Goto the @Playender label

@MenuExit ""The Exit selection on the menu
cls ""Clear the screen
PRINT " Play" ""Show play is not selected
PRINT ">Exit" ""Show Exit is selected
wait 8 "" Wait so it doesn't go SUPER fast!
goto @MenuExitCon ""Goto the controls for @MenuExit

@MenuExitCon ""The controls for the Exit selection AKA @MenuExit
button() = b ""Sets that Button is B
if (b and 1) goto @Menu ""1 is up, so if up is pressed then goto @Menu AKA the Play option
if (b and 16) goto @Playender ""If A is pressed, then goto the @Playender label
goto @MenuExitCon ""Loop the controls, so the player has unlimited time to press a button

@Playender ""Set the @Playender Label
end ""End the program, so when A is pressed on exit option the program ends

Thanks for reading! Next tutorial soon!

Comments, questions, reply below or email moomantri@yahoo.com


Last edited by boxtropica on Fri Sep 21, 2012 5:34 pm; edited 2 times in total
boxtropica
boxtropica
Admin

Posts : 26
Join date : 2012-09-06

https://conlogxl.forumotion.com

Back to top Go down

Tutorial from a Box #2 Labels, Loops, and Input Empty Re: Tutorial from a Box #2 Labels, Loops, and Input

Post  JCHero Wed Sep 19, 2012 7:53 pm

Hmmm I don't know why but when I start the program it says

>PLAY
EXIT
Syntax error (8)
OK

Could you help me Sad I double check and everything is written as in the example Sad and I can't fix the problem by myself XD not yet ^^'

JCHero

Posts : 6
Join date : 2012-09-12

Back to top Go down

Tutorial from a Box #2 Labels, Loops, and Input Empty Re: Tutorial from a Box #2 Labels, Loops, and Input

Post  GrabSomeEyes Thu Sep 20, 2012 9:01 pm

Great!
Can't wait to get started on this!
I'm actually planning on using this to start making my first... ehem... program worth making?
I'm thinking about programming a basic English - Spanish phrasebook sort of thing now, so it'd be good to have a way to create a menu.
GrabSomeEyes
GrabSomeEyes

Posts : 29
Join date : 2012-09-08
Age : 26

Back to top Go down

Tutorial from a Box #2 Labels, Loops, and Input Empty Re: Tutorial from a Box #2 Labels, Loops, and Input

Post  GrabSomeEyes Thu Sep 20, 2012 9:45 pm

JCHero wrote:Hmmm I don't know why but when I start the program it says

>PLAY
EXIT
Syntax error (8)
OK

Could you help me Sad I double check and everything is written as in the example Sad and I can't fix the problem by myself XD not yet ^^'
That's interesting because I just got a syntax error on line 2...
EDIT: I wrote DS instead of CLS. I was wondering...
EDIT2: So. Syntax error (9) now...
I think we've got the same problem with the buttons for some reason.
EDIT3: I fixed the syntax error by changing "BUTTON()=B" to "VARIABLE=BUTTON(B)" HOWEVER I cannot select anything off the menu now.
EDIT4: Took a peak at Galaxy 0.1.1's code, sure you didn't mean B=BUTTON() ?
Seems to me like you just misplaced the B=, no big deal. Going to try editing my menu right now.
EDIT5: So. I got it to work a bit better, but as soon as I started it I tried going down and got "Undefined label (12, IF)" so I'll be fixing that now.
EDIT6 (Final edit...): Couldn't figure out the problem. Giving up for the night, looked back at my program, when I selected the first option it gave me:
"COMING SOON!" as I told it to do, and
"Undefined label (18, GOTO)
OK" which I definitely didn't tell it to do.
GrabSomeEyes
GrabSomeEyes

Posts : 29
Join date : 2012-09-08
Age : 26

Back to top Go down

Tutorial from a Box #2 Labels, Loops, and Input Empty Re: Tutorial from a Box #2 Labels, Loops, and Input

Post  JCHero Fri Sep 21, 2012 3:46 pm

In the tutorial it says to write BUTTON()=B but wetting it like this is an error, you have to write B=BUTTON() and it will work. Now my menu works well and I also changed the color of my menu.

So BUTTON()=B is wrong
B=BUTTON() is good. DSi

I love the emoticons Evil or Very Mad Wink cheers santa

JCHero

Posts : 6
Join date : 2012-09-12

Back to top Go down

Tutorial from a Box #2 Labels, Loops, and Input Empty Re: Tutorial from a Box #2 Labels, Loops, and Input

Post  boxtropica Fri Sep 21, 2012 5:33 pm

JCHero wrote:In the tutorial it says to write BUTTON()=B but wetting it like this is an error, you have to write B=BUTTON() and it will work. Now my menu works well and I also changed the color of my menu.

So BUTTON()=B is wrong
B=BUTTON() is good. DSi

I love the emoticons Evil or Very Mad Wink cheers santa

Ah! Haha, It's been a few weeks since I last programmed with Petit Computer, so I'm a little rusty! I'll take a mental note to refresh my memory a little before making another tutorial next time, thanks!
boxtropica
boxtropica
Admin

Posts : 26
Join date : 2012-09-06

https://conlogxl.forumotion.com

Back to top Go down

Tutorial from a Box #2 Labels, Loops, and Input Empty Re: Tutorial from a Box #2 Labels, Loops, and Input

Post  GrabSomeEyes Fri Sep 21, 2012 10:43 pm

It took me a while to realize what was wrong with the button command.
Now my menu just acts weird, and I can't get it to go to any exit commands or anything. :I

EDIT: So I fixed the undefined label issue with adding a WAIT (for some reason I forgot to add one [it wasn't the problem anyway, it just went way too fast]), and by changing the @PLAYEND (which is @ALPHABETEND in my coding) to @MENU so it just goes back to the menu.
HOWEVER...
Whenever I so much as highlight over the "Exit" on the menu it immediately ends the program without warning.
EDIT: Fixed it... just a different label. (Kind of figured considering it flat out told me, too dumb to check though).
I'm an idiot.
GrabSomeEyes
GrabSomeEyes

Posts : 29
Join date : 2012-09-08
Age : 26

Back to top Go down

Tutorial from a Box #2 Labels, Loops, and Input Empty Re: Tutorial from a Box #2 Labels, Loops, and Input

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum