Basic course for newbies

Page 1/11
| 2 | 3 | 4 | 5 | 6

Par Vampier

Prophet (2296)

Portrait de Vampier

20-12-2013, 03:34

I've always wanted to start a topic to have a simple basic course for newbies. So I finally decided to set something up.

Let's start with the basics first Wink

1) variables
2) output to the screen
3) user input
4) decisions

Variables

a=12345
print a

This assigns a value of 12345 to the variable name a

a$="hello world"
print a$

In case you want to assign a string to a variable we use a $ at the end. So in this case a$

Now also try
print a,a$
You will see that a and a$ still both have the values

Output to the screen
Let's just limit ourselves to text output for now.

In the previous example we used 'print'. Print does exactly what it says... it prints to the screen Running Naked in a Field of Flowers

(in the next examples we type new to clear out the previous basic program that's in your memory. This can't be undone easily to use this with caution!

Anyway try this:

new
10 print "hello world":goto 10

To stop this push the ctrl and stop keys at the same time.

User Input
To get user input we use the command input here is an example:

new
10 print"What is your name";A$
20 print "hello ";a$

Alternatively you can use lineinput instead of input

You can also read the keyboard input

new
10 print inkey$:goto 10

When you run push a few keys on the keyboard you'll see letters scroll up the screen.
To stop this push the ctrl and stop keys at the same time.

We can also get keyboard input for the joystick and cursor keys.

new
10 print stick(0):goto10

Push the cursor keys. To stop this push the ctrl and stop keys at the same time.

decisions

A program needs to make decisions on the input whic is given to it. Try this

new
10 input "give a number less than 10";a
11 if a<10 then print "thanks!"
12 if a=>10 then print "this is 10 or more!"
13 goto 10

Try giving in a few numbers ranging between 0 and 50.
To stop this push the ctrl and stop keys at the same time.

Now let's finish this lesson with a cool example:

new
100 SCREEN0:COLOR15,0,0
110 D=STICK(0):'keyboard
120 IF D=1 THEN A$="up"
130 IF D=5 THEN A$="down"
140 IF D=7 THEN A$="left"
150 IF D=3 THEN A$="right"
160 IF D=8 THEN A$="left up"
170 IF D=6 THEN A$="left down"
180 IF D=2 THEN A$="right up"
190 IF D=4 THEN A$="right down"
200 PRINT D,A$
210 GOTO 110

Let me know what you think Smile

!login ou Inscrivez-vous pour poster

Par Vampier

Prophet (2296)

Portrait de Vampier

20-12-2013, 05:12

Forgot to mention:

The basic command 'list' will give you the program (or press f4+enter)
To run a program simply type 'run' (or press f5)

Par Vampier

Prophet (2296)

Portrait de Vampier

20-12-2013, 07:22

I wish I could change the page somewhat longer

Here is something that's still wrong:

User Input
To get user input we use the command input here is an example:

new
10 input"What is your name";A$
20 print "hello ";a$

Par ericb59

Paladin (859)

Portrait de ericb59

20-12-2013, 07:55

it's a good idea for newbies.
But, I think this will be more readable on a wiki than on forum Topic...

Par wolf_

Ambassador_ (9767)

Portrait de wolf_

20-12-2013, 08:49

..and easier to find/organize. In fact we do have a list o' commands in our Wiki already, how about expanding those?

Par wolf_

Ambassador_ (9767)

Portrait de wolf_

20-12-2013, 08:52

Here: http://www.msx.org/wiki/Category:MSX-BASIC_COMMANDS to be exact.

If you want to make a bit more of a natural story, rather than chapters by command, can you make a new category for that in here: http://www.msx.org/wiki/MSX-BASIC and fill 'r up? :)

Par NYYRIKKI

Enlighted (5358)

Portrait de NYYRIKKI

20-12-2013, 20:20

Very nice, keep up the good work! Although there are plenty of good books that cover all these basics there is very little online tutorials.

Vampier wrote:

Now let's finish this lesson with a cool example:

new
100 SCREEN0:COLOR15,0,0
110 D=STICK(0):'keyboard
120 IF D=1 THEN A$="up"
130 IF D=5 THEN A$="down"
140 IF D=7 THEN A$="left"
150 IF D=3 THEN A$="right"
160 IF D=8 THEN A$="left up"
170 IF D=6 THEN A$="left down"
180 IF D=2 THEN A$="right up"
190 IF D=4 THEN A$="right down"
200 PRINT D,A$
210 GOTO 110

Let me know what you think Smile

FORI=2TO8:XD(I)=SGN(5-I):YD(8-I)=XD(I):NEXT:SWAPYD(0),YD(8): SCREEN2,1:SPRITE$(0)="0HH0":FORI=0TO1:S=STICK(J):I=-STRIG(J): X=X+XD(S):Y=Y+YD(S):PUTSPRITE0,(X,Y),8:NEXT

I'm very sorry, but that is just me...

Par Vampier

Prophet (2296)

Portrait de Vampier

20-12-2013, 20:39

NYYRIKKI what part of 'newbies' did you not see Smile

Par Walter.MSX

Expert (72)

Portrait de Walter.MSX

20-12-2013, 20:46

A good reminder of the simple basics to start may encourage a programmer. Smile
I think there are not enough NYYRIKKI in the MSX World.

Very good idea to open this topic, Vampier ! Wink

Par NYYRIKKI

Enlighted (5358)

Portrait de NYYRIKKI

20-12-2013, 20:56

I just shared the "Let me know what you think" part...

Par edoz

Prophet (2171)

Portrait de edoz

20-12-2013, 21:10

Cool Topic. I will follow it ! So far everything is clear to me Smile .. I hope to learn more about the poke and peek also. And maybe some assembly ?

But this part is a bit complex Wink Please explain Big smile

FORI=2TO8                     'What i understand.. count from 2 till 8 in I
     XD(I)=SGN(5-I)           'Then set a array in XD with SGN ? What is SGN
     YD(8-I)=XD(I)             ' No idea .. but set YD(8-I) the value of XD(I)
NEXT
SWAP YD(0),YD(8)          'Then SWAP something ?
SCREEN2,1      
SPRITE$(0)="0HH0"        'SomeHex value used for the sprite ?
FORI=0TO1                   'Loop something 1 time ?
     S=STICK(J)
     I=-STRIG(J)             'What is strig ?
      X=X+XD(S)
     Y=Y+YD(S)
PUTSPRITE0,(X,Y),8      'Put the sprite on the screen 
NEXT

Maybe it's better to start at the begin... "Hello World!" Big smile

Page 1/11
| 2 | 3 | 4 | 5 | 6