This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-12 17:57:42

DrEvilCheezi
Scratcher
Registered: 2012-09-01
Posts: 2

How to make notepad program?

How do I make a notepad program where I type something and a the letter goes on the screen without lists?

Offline

 

#2 2012-12-12 20:53:34

SheppardProductions
Scratcher
Registered: 2011-08-14
Posts: 100+

Re: How to make notepad program?

A sprite with each letter as a costume. Hide it. The next step I can't really explain w/o an example:

when gf clicked
hide
forever
if (key A pressed)
switch to costume (A)
stamp
Then have the sprite move forward after each letter typed. If you wanted you could use a conditional variable regarding capitalization.

Offline

 

#3 2012-12-12 21:53:41

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How to make notepad program?

You'll have to make it move over a certain amount of "x" every character and then move down a line and start back on the left side too.  This is easiest with monospaced font.  Essentially, after stamping a character, the sprite moves over by the width of the character and, if it is over the right-most margin, it resets is x position to the left-most margin.  I would also keep track of what is typed using a variable.  If I could add to the above script:

when gf clicked
clear
hide
set [text v] to ()
go to x:(left margin) y:(top margin)
forever
if<key [a v] pressed?>
set [text v] to (join (text)[a])
switch to costume [a v]
show
stamp
hide
change x by ([width of a]+[2]) // the "2" is a slight buffer space between characters
if<(x position) > (right margin)>
set x to (left margin)
change y by (((-1)*[height of text])-[height of vertical buffer])
end
end
if<key [b v] pressed?>
set [text v] to (join (text)[b])
switch to costume [b v]
etc.
end
if<key [c v] pressed?>
set [text v] to (join (text)[c])
switch to costume [c v]
etc.
end
The above script won't accept key strokes like a "normal" text editor, but should still offer the general effect.

If you want to be able to delete text, you'll naturally need a more complicated script and, as you probably know, creating a text editor using Scratch already involved a LOT of coding.

I've never programed a cursor into any of mine, but if you want that I could try.  The downside being that, as of now, it seems that it would require re-stamping all of the text whenever you wanted to insert/delete text from the middle of the document, and you'd probably have to use Turbo speed.

P.S. Do you know about the ask () and wait block, because it basically has everything you could want in a text editor, except that it only accepts a single line of text and probably doesn't stylistically fit your needs.

Last edited by MoreGamesNow (2012-12-12 21:55:43)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#4 2012-12-13 00:36:36

DrEvilCheezi
Scratcher
Registered: 2012-09-01
Posts: 2

Re: How to make notepad program?

what is the etc.?

Offline

 

#5 2012-12-13 16:27:32

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How to make notepad program?

It means that the script used in the "if key a pressed" part is pretty much duplicated.  Of course you'd change the width of the letter, but the rest of it should be pretty much the same.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer