Jump to content



Photo
- - - - -

Casio BASIC Tutorial


  • Please log in to reply
24 replies to this topic

#1 CrimsonCasio

CrimsonCasio

    UCF Ambassador

  • [Legends]
  • PipPipPipPipPipPipPipPipPipPip
  • 3579 posts
  • Gender:Male
  • Location:USA
  • Interests:Claculators, Stephen King, Video Games, Calculators, Programming, Calculators, Reading, Calculators... hmm, what else... Ah! Calculators!

  • Calculators:
    Algebra FX2.0, CFX 9850Ga+, Classpad 300

Posted 25 April 2003 - 12:00 AM

Here is the next installment, with this you start learning some important stuff so make sure you understand... everything in game programming (or any programming) revolves around these next few chapters. B)

PART 5: Selection Statements

Selection Statements are used to make programs have differing outcomes, instead to executing the same way every time they are run.  A selection statement checks an expression, sees if it is True or False, then if True executes the rest of the statement otherwise it skips to below the statement and continues with execution.

There are two types of selection statements on the calculator, but one can only be used on models before the AFX series. They are the If/Else statement and the => arrow.

An If/Else statement works like this

1->A
If A=1 	 //expression to be evaluated
Then ?HI?  //result if expression is true
?HOW ARE YOU?
Else ?BYE?  //result if expression is false
?SEE YOU LATER?
If End 	 //end of statement

Result:
Since A is 1 the statement evaluates to true, therefore

HI
HOW ARE YOU

Is printed.  If you replaced the first line with 0->A then the if statement would evaluate to False, and

BYE
SEE YOU LATER

Would be printed.

An If statement can contain many different things, and can be many lines long, they are the keystone to making a game, and before going on you should feel comfortable using them.

The => arrow is also very useful, it is a single line selection statement that takes up less space but can do less than a normal if/else.

This is the same code as above, except using the => arrow instead of the if statement.

1->A
A=1=>?HI?
A=1=>?HOW ARE YOU?
A<>1=>?BYE? 	 // <> means not equal to
A<>1=>?SEE YOU LATER?

Neat huh?  As you can see, the => arrow provides cleaner looking code, and occasionally takes up less space than the if statement.  In general, the best time to use a if statement is when you have at least to lines of code to be put inside, otherwise use the => arrow.

PART 6: Advanced Loops

Now that you have a good understanding of both loops and selection statements I will go into the more advanced features of both.

First off we?ll talk about nesting.  Nesting is when you take one loop and put it inside another.  Here is an example:

0->C
For 1->A To 10  //Step can be omitted instead of using Step 1
For 1->B To 10
A+B+C->C
Next
Next
C_ 	 // the _ represents the output sign, it displays whatever is before it and
    Pauses until [EXE] is pressed.

By executing this code you will get this output:

1100
  Disp  //caused by _

Now we will go through the code and look at what each line does.
Line 1:  0->C
Assigns the value 0 to the variable C
Line 2:  For 1->A To 10
Tells the program that you will be looping until A is equal to 10, adding 1 with each loop.
Line 3:  For 1->B To 10
Tells the program that you will be looping until B is equal to 10, adding 1 with each loop.
Line 4: A+B+C->C
The current value in A will be added to the current value of B, that value is then added to the current value of C and then assigned to C.
Line 5: Next
Goes to line 3.
Line 6: Next
Goes to line 2.
Line 7: C_
Displays the final value of C.

As you can see, the second loop executes completely for each iteration (loop) of the first loop.

Nesting also applies to selection statements, you can nest if or => inside each other as needed.
Example:

A<1=>A>0=>?HI?
If A<1
Then if A>0
Then ?HI?
End If
End If

This brings us to another point: 

Part 7: Logical Operators

As you have just seen, there are times when you will want more than one condition in a selection or loop, you can nest the statements or you can use a logical operator: And, Or, Not.

And and Or are operators which can be used in selection statements to specify additional conditions, therefore the code above could be written:

A<1 and A>0=>?HI?

Instead of:

A<1=>A>0=>?HI?

The Or operator allows you to specify alternate conditions which are evaluated independently and if any are true then the entire statement is considered true.  This means you can do this:

If A=1 Or B=1
Then ?TRUE?
End If

When this executes it will print TRUE if A or B equals 1.  Handy huh?

The Not operator can also be used in selection statements, though it is not used nearly as often.  Not returns False if the statement is true (or 1) and True if the statement is False (or 0) so:

If Not (A=1)
Then ?TRUE?
End If

This will print true if A is any number but 1.  In this case the Not statement is used as an <> (not equal to) statement, but it has other uses. We will cover more on this later.


#2 Bob Vila

Bob Vila

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 768 posts
  • Gender:Male
  • Location:USA

  • Calculators:
    FX 1.0+ : CFX-9850 GB Plus : TI-81

Posted 25 April 2003 - 01:28 AM

nice, keep them comin :)

#3 rjstephens

rjstephens

    Casio Freak

  • Members
  • PipPipPipPip
  • 239 posts
  • Location:Brisbane, Queensland, Australia

  • Calculators:
    CFX9850GB+

Posted 25 April 2003 - 10:46 AM

if statements

reminds me of when i tried to write a program on pc (i was 6) to add two numbers from one to ten. that was before i learned how to do numeric variables - i learned strings first.

it was something like

input x$
input y$

if x$="1" and y$="1" then print "2"

etc
etc

i never finished it.

#4 CrimsonCasio

CrimsonCasio

    UCF Ambassador

  • [Legends]
  • PipPipPipPipPipPipPipPipPipPip
  • 3579 posts
  • Gender:Male
  • Location:USA
  • Interests:Claculators, Stephen King, Video Games, Calculators, Programming, Calculators, Reading, Calculators... hmm, what else... Ah! Calculators!

  • Calculators:
    Algebra FX2.0, CFX 9850Ga+, Classpad 300

Posted 25 April 2003 - 11:06 AM

boy rj, I'm not sure my tutorial can help you. :lol:

#5 Netforce

Netforce

    Casio Fan

  • Members
  • PipPip
  • 44 posts

  • Calculators:
    Casio CFX-9850GB Plus

Posted 25 April 2003 - 11:11 AM

Very nice tutorial!
CrimsonCasio; thanks for your permission. I will publish it on CasioCorner as soon as the whole article is ready. Thanks again and good luck!

#6 Pixter

Pixter

    Casio Fan

  • Members
  • PipPip
  • 43 posts
  • Location:The Netherlands
  • Interests:casio, visual basic, lego mindstorms and formula 1.

  • Calculators:
    cfx9850gb plus

Posted 26 April 2003 - 09:24 AM

This is GREAT! :D

#7 genesis

genesis

    UCF BASIC Programming Runner Up

  • Super Member
  • PipPipPipPip
  • 281 posts
  • Location:Perth, Australia
  • Interests:Speaking German, computers, defending CFX calculators...

  • Calculators:
    CFX 9850 GB+

Posted 28 April 2003 - 02:09 AM

OH MY GOD!!!

You didn't know that???

I've been programming with Menu returns since the Dark Ages!!!!

Nearly all of my programs have a quit menu with the simple command 'Stop' (or 'Disp' may work) and some text on the screen so the user can decide whether to Restart (EXE), goto the Menu (MENU) and Shut Down (Shift + AC). And what's so good about that? Don't you set you hopes a little higher?

P.S. For rjstephens, if you work on calc under one of the sections (e.g. PROG, RUN etc.) and return to the menu, when you go back, everything will be as you left it and not the default screen.

In fact, I'm going to post a new topic with programming tips...

#8 PJay

PJay

    Casio Freak

  • Members
  • PipPipPipPip
  • 260 posts
  • Gender:Male

  • Calculators:
    Casio fx-991ES Plus

Posted 23 August 2003 - 03:37 AM

I can't find "=>" ! :unsure: Please help me ! :hammer:

#9 casiokingdom

casiokingdom

    UCF BASIC Programming 2nd Place

  • Members
  • PipPipPipPipPipPipPip
  • 782 posts
  • Gender:Male
  • Location:Perth, WA, Australia

  • Calculators:
    CFX-9850GB PLUS WE, fx-9860G AU

Posted 23 August 2003 - 03:42 AM

press, shift, vars, jump, F3

#10 PJay

PJay

    Casio Freak

  • Members
  • PipPipPipPip
  • 260 posts
  • Gender:Male

  • Calculators:
    Casio fx-991ES Plus

Posted 23 August 2003 - 04:16 AM

press, shift, vars, jump, F3

What ? :ph34r:
"Isz" ? :rolleyes:

#11 casiokingdom

casiokingdom

    UCF BASIC Programming 2nd Place

  • Members
  • PipPipPipPipPipPipPip
  • 782 posts
  • Gender:Male
  • Location:Perth, WA, Australia

  • Calculators:
    CFX-9850GB PLUS WE, fx-9860G AU

Posted 23 August 2003 - 05:10 AM

yeah, you wanted to know where the => command is.

I'll restate it: Press shift, vars, F3, F3

#12 PJay

PJay

    Casio Freak

  • Members
  • PipPipPipPip
  • 260 posts
  • Gender:Male

  • Calculators:
    Casio fx-991ES Plus

Posted 23 August 2003 - 12:04 PM

yeah, you wanted to know where the => command is.

I'll restate it: Press shift, vars, F3, F3

In AFX 2.0+ ? :hammer:

#13 CrimsonCasio

CrimsonCasio

    UCF Ambassador

  • [Legends]
  • PipPipPipPipPipPipPipPipPipPip
  • 3579 posts
  • Gender:Male
  • Location:USA
  • Interests:Claculators, Stephen King, Video Games, Calculators, Programming, Calculators, Reading, Calculators... hmm, what else... Ah! Calculators!

  • Calculators:
    Algebra FX2.0, CFX 9850Ga+, Classpad 300

Posted 23 August 2003 - 12:09 PM

that isn't in the AFX, you can replace it with an If then statement (i beleive i covered this in the tutorial).
so this (A=1=>2->A) becomes (if A=1:Then 2->A:IfEnd). note that you can replace the colons with line breaks.

if you have a link cable you can upload a program that has the => in it then use copy/paste to use it in your programs.

#14 PJay

PJay

    Casio Freak

  • Members
  • PipPipPipPip
  • 260 posts
  • Gender:Male

  • Calculators:
    Casio fx-991ES Plus

Posted 23 August 2003 - 12:12 PM

Yes, I have a link cable (Casio SB-87 Cable) . What's the program ?

#15 CrimsonCasio

CrimsonCasio

    UCF Ambassador

  • [Legends]
  • PipPipPipPipPipPipPipPipPipPip
  • 3579 posts
  • Gender:Male
  • Location:USA
  • Interests:Claculators, Stephen King, Video Games, Calculators, Programming, Calculators, Reading, Calculators... hmm, what else... Ah! Calculators!

  • Calculators:
    Algebra FX2.0, CFX 9850Ga+, Classpad 300

Posted 23 August 2003 - 12:14 PM

just any... you can use the FA-123 to create a program that only has the => just look for it in the menus.

#16 Brazzucko

Brazzucko

    UCF BASIC Programming Champion

  • Super Member
  • PipPipPipPipPipPip
  • 412 posts

  • Calculators:
    FX 1.0, CFX 9850 GB Plus and FX 9750G

Posted 23 August 2003 - 01:48 PM

:D Well for guys that know BASIC those tutorials are boring to make, so congratulations for your work Crimson and patience for do it??

#17 PJay

PJay

    Casio Freak

  • Members
  • PipPipPipPip
  • 260 posts
  • Gender:Male

  • Calculators:
    Casio fx-991ES Plus

Posted 23 August 2003 - 02:56 PM

just any... you can use the FA-123 to create a program that only has the => just look for it in the menus.

How ? :unsure:

#18 ross8653

ross8653

    Casio Addict

  • Members
  • PipPipPip
  • 96 posts
  • Location:over the river and through the woods
  • Interests:paintball

  • Calculators:
    9850 fx2.0

Posted 24 August 2003 - 05:00 AM

you upload any prog to your calc with the => already in there then you copy and paste it out
my game "whack it" has a few of them in there, here's a direct link for ya
http://www.geocities...ams/whackit.zip

#19 PJay

PJay

    Casio Freak

  • Members
  • PipPipPipPip
  • 260 posts
  • Gender:Male

  • Calculators:
    Casio fx-991ES Plus

Posted 29 August 2003 - 10:48 AM

you upload any prog to your calc with the => already in there then you copy and paste it out
my game "whack it" has a few of them in there, here's a direct link for ya
http://www.geocities...ams/whackit.zip

I can't find it ! :(

#20 betoe

betoe

    UCF Spanish Translator

  • [Legends]
  • PipPipPipPipPipPipPip
  • 846 posts
  • Gender:Male
  • Location:Guadalajara/Mazatlan, Mexico.
  • Interests:Electronics, SW development, automotive. Swim->bike->run

  • Calculators:
    Algebra FX2.0 (R.I.P.), Classpad 300

Posted 29 August 2003 - 06:36 PM

@ PJ:

Try this:
http://www.geocities...whackit.zip?1=1

#21 CrimsonCasio

CrimsonCasio

    UCF Ambassador

  • [Legends]
  • PipPipPipPipPipPipPipPipPipPip
  • 3579 posts
  • Gender:Male
  • Location:USA
  • Interests:Claculators, Stephen King, Video Games, Calculators, Programming, Calculators, Reading, Calculators... hmm, what else... Ah! Calculators!

  • Calculators:
    Algebra FX2.0, CFX 9850Ga+, Classpad 300

Posted 29 August 2003 - 08:11 PM

that doesn't work, try http://www.geocities...rafx2/programs/

#22 PJay

PJay

    Casio Freak

  • Members
  • PipPipPipPip
  • 260 posts
  • Gender:Male

  • Calculators:
    Casio fx-991ES Plus

Posted 30 August 2003 - 08:47 AM

NO ! :huh: I can't find "=>" in "whack it" :(

#23 ross8653

ross8653

    Casio Addict

  • Members
  • PipPipPip
  • 96 posts
  • Location:over the river and through the woods
  • Interests:paintball

  • Calculators:
    9850 fx2.0

Posted 30 August 2003 - 09:32 AM

um... you probably put more time into posting that you cant find it than if you just looked through it for 2 minutes.
there's a bunch of them in there all i can suggest is look harder

#24 CrimsonCasio

CrimsonCasio

    UCF Ambassador

  • [Legends]
  • PipPipPipPipPipPipPipPipPipPip
  • 3579 posts
  • Gender:Male
  • Location:USA
  • Interests:Claculators, Stephen King, Video Games, Calculators, Programming, Calculators, Reading, Calculators... hmm, what else... Ah! Calculators!

  • Calculators:
    Algebra FX2.0, CFX 9850Ga+, Classpad 300

Posted 30 August 2003 - 12:31 PM

look harder, I found one in just a few seconds.

\Text X,11,"\->":\Do
\Getkey\->G:\LpWhile \ Not G
\Text X,9," "
G=28\ And X\<>28\=>X-7\->X //here =>
G=37\ And X\<>49\=>X+7\->X
\LpWhile G\<>31
X=49\=>\Goto3
\If X=42
\Then \ClrText
" HIGH SCORES"

#25 PJay

PJay

    Casio Freak

  • Members
  • PipPipPipPip
  • 260 posts
  • Gender:Male

  • Calculators:
    Casio fx-991ES Plus

Posted 01 September 2003 - 03:25 PM

Yes, I found it.
Thank You :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users