Author Topic: how to make a tutorial  (Read 2247 times)

0 Members and 1 Guest are viewing this topic.

Offline bored_student

  • LV3 Member (Next: 100)
  • ***
  • Posts: 44
  • Rating: +3/-0
    • View Profile
how to make a tutorial
« on: September 18, 2013, 05:52:31 am »
I thougth of making an tutorial for how to get an input string in Axe without the use of input()
and I don't know if there are any specifications of  how to make it.
sadly there isn't a tutorial about how to make a tutorial  ::)

PS: I don't even know if this is the correct Section to ask this question. I'm sorry if I made something wrong
Sorry for my bad English, I'm German.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: how to make a tutorial
« Reply #1 on: September 18, 2013, 06:08:18 am »
I guess making a step by step list with screenshots when needed, is a good start.
As long as it's clear and understood by most, I think it's good :)

After the steps, maybe a "FAQ" and "Common issues" sections can be good
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline bored_student

  • LV3 Member (Next: 100)
  • ***
  • Posts: 44
  • Rating: +3/-0
    • View Profile
Re: how to make a tutorial
« Reply #2 on: September 18, 2013, 12:21:30 pm »
You want an user to input a string and the 'input' routine
from Axe doesn't suit you because..
1. ..the input is on the first line of the display
2. ..the input can't be interrupted or influenced
3. ..while inputting your programm can't draw something other
     to the screen
4. ..the input is only large sized font
5. ..the user can type all tokens he want to
6. ..the input returns a string of OS tokens not of characters (look
     Axe command list)
then just read on.

I will show you how to make a input routine that
1. ..can be drawn everywhere at the screen in small or large sized font
2. ..can be innterrupted, influenced, overdrawn while inputting
3. ..takes a AscII - character input with just those keys and chars you want
     the user to input
4. ..lets your programm do something other while inputting

Let's start

The simpliest way to get all the key inputs would be
to just make a long construction If getKey()... for each Key.

Since this is unoptimized and results in big programm sizes,
I want to show you a better way to do this.

First let's make an input loop that runs until someone presses
2nd to exit

Code: [Select]
Reapeat getKey(54)
...
End

In Axe there is a command getKey (without any brackets) which
"returns the last key pressed or zero if no keys are pressed"
Axe command list

Code: [Select]
getKey -> K

Now let's take a look at the Axe keycodes.
These numbers are copied from the keycodes.png in Axe download pack
    
5352515049
545556
484032
47 - 'A'39 - 'B'31 - 'C'2315
46 - 'D'        38 - 'E'        30 - 'F'        22 - 'G'        14 - 'H'        
45 - 'I'37 - 'J'29 - 'K'21 - 'L'13 - 'M'
44 - 'N'36 - 'O'28 - 'P'20 - 'Q'12 - 'R'
43 - 'S'35 - 'T'27 - 'U'19 - 'V'11 - 'W'
42 - 'X'34 - 'Y'26 - 'Z'1810
4133 - ' '25179

I have written the characters we want the user to input beside
the corresponding keys.
As you can see if we process key inputs from 11 to 47 we can
detect all the character keys plus the space key which is 33.
But how can we find the AscII-character now that we know the key.
Take a look at this:

Code: [Select]
"WRMH" -> Str1
[00 00 00]
"VQLG"
[00 00 00]
"ZUPKFC"
[00]
" YTOJEB"
[0000]
"XSNIDA"

Have you already figured out what I want to tell you with these "XFCZPS" and
so on? Let me explain: First we just have the key code in variable K.
Now we subtract 11 from it since only key inputs from 11 to 47 are interesting.
If someone presses key 12='R' , the number 12 is stored in K. 11 subtracted
equals 1.
Now the simple operation Str1+1 picks the 'R' right out of the bunch of chars we
have in Str1. This procedure is the same for 'W', 'M' and 'H'.
But there is a problem. If key 15='Clear' is pressed you probably don't want a
character added to your input string. Solved this with a zero at the place in
Str1 where K=15 would point. So let's make 4 zero bytes for the keys 15,16,17
and 18 after "WRMH" since there are no characters. (I know there is no key 16
but still let's pretend there is)
Of course you may link some different tokens to those keys (not key 16 :))
There is a thing I should mention. As I said we need 4 zero bytes but there are
only 3 of them. This is because the  -> Str1  already adds an ending zero to
the "WRMH". Later on (for example after "VQLG") this isn't done so we put the
full number of zeros there.

By the way, feel free to play around with different characters and keys to fit
the input program into your needs.

To implement lowercase input as well just make the data above with lowercase
characters.

Enough theorie, let's code:

Code: [Select]
"WRMH" -> Str1U     .Uppercase characters
[00 00 00]
"VQLG"
[00 00 00]
"ZUPKFC"
[00]
" YTOJEB"
[0000]
"XSNIDA"

"wrmh" -> Str1L        .Lowercase characters
[00 00 00]
"vqlg"
[00 00 00]
"zupkfc"
[00]
" ytojeb"
[0000]
"xsnida"

Fix1:Fix5    .Draws big font to the frontbuffer instead of small font to the screen

.Prepare the frontbuffer and draw a textfield
ClrDraw
Rect(22,26,51,11)
WRect(23,27,49,9)

.First the cursor position (zero at the beginning)
0 -> C
0 -> F       .The lowercase flag, 0 means uppercase, 1 means lowercase
0 -> B       .This is our "Blink counter" it is increased every loop and
             .makes the cursor blink

.We need a place to put our input string, I will take L1. reserve 9 bytes for
.a 8 char string (plus ending zero)
Fill(L1, 9, 0)

Repeat getKey(54)     .the loop from above
 getKey -> K

 ...
 Here I will later add the cursor movements
 ...

 If K=48        .The Alpha Key is pressed
  A=0 -> A      .change A from 0 to 1 or the other way, since an alpha-press
                .should always change from uppercase to lowercase or the other way
 End

 K-11 -> K
 If K < 37    .we want the last key to be 47 'A' minus 11 equals 36
  If {K+(F?Str1L,Str1U)}     .if F=0 we take the char from Str1U else from Str1L
  -> {C+L1}                  .add it to the input string if its not zero
   If C<7
    C++           . move the cursor if there is enougth space (remember we just
                  . reserved 8 bytes to fill with our input)
   End
  End
 End

 WRect(23,27,49,9)     .Clears the textfield
 Text(24,28,L1)        .Draws the input string to the frontbuffer
 B++                   .Let's blink the cursor
 If B^64>31            .The cursor should blink not every loop but every 64th
                       .Play around with these values to fit your cursors speed
  Text(C*6+24, 28, (F?227,226)>Char)
  ...Let me explain if F=0 (Uppercase) Char(226) is displayed this is the uppercase
     cursor. Else (Lowercase) Char(227) the lowercase cursor is drawn to the buffer
  ...
 End
 DispGraph             .This is a very complicated command which draws the frontbuffer
                       .to the screen in a mysterious way (So just add it and enjoy :))
End

Fix0:Fix4            .Resets the Fixes

The input string is now in L1 you can do what you want with it.
For Example disp the string
Code: [Select]
Disp L1,i
draw it to the buffer  ;remember to set Fix5 (and Fix1 if you want to draw large font)
Code: [Select]
Text(X,Y,L1)
or create an appvar (put a 21 to the first byte):
Code: [Select]
Copy(L1,L1+1,9)^r     .^r to copy it backwards. This way it doesn't override itself
21 -> {L1}            . the appv token
GetCalc(L1, 120)      .Creates a user named appvar 120 bytes long


So this is my first tutorial  :D
Maybe some of you could go through it to help me improve it (also the english, I'm sure I made mistakes)  :-\
« Last Edit: September 18, 2013, 12:27:46 pm by bored_student »
Sorry for my bad English, I'm German.