m (spelling error)
 
(24 intermediate revisions by 15 users not shown)
Line 1: Line 1:
==What A Typewriter Simulator Is==
+
A typewriter simulator is a [[Simulation Projects|simulation project]] where you can type notes, like in a word processor. This typewriter tutorial only requires simple scripting.
A typewriter simulator is a [[Simulation_Projects|simulation project]], where you can type to write notes, like Microsoft Word©. They do take a little while to make, but the scripting is simple.
 
  
==How To Make One==
+
==Creation==
===Step 1===
+
First, create a [[sprite]]. One can call it whatever the user wants to, but for this example, it will be called "Text".
First, create a sprite. You can call it whatever you want, but for our example, we'll call it "Text".
 
  
===Step 2===
+
Now, click the [[Costumes]] button above the block palette, and change the mode to [[vector]]. One will need to create a new costume with the letter "a", uppercase or lowercase. Name the costume "a".
Now, click the "<span style="color:#616161">Costumes</span>" button above the block palette, and change the mode to vector. Now, type the letter "a", uppercase or lowercase. Name the costume "a".
 
  
===Step 3===
+
Create 25 more costumes, but instead of making more "a"s, make one costume for each letter of the alphabet. The name of each costume should be the letter that the costume is.
Repeat step 2 listed above 25 more times, except with different letters of the alphabet. First you do "a", then "b", and so on.
 
  
===Step 4===
+
Once the user has all of the costumes, create a [[Custom Block|custom block]] that looks like this:
Now that you have all of the costumes, click the "<span style="color:#616161">Scripts</span>" button, right next to the "<span style="color:#616161">Costumes</span>" button. Go to the <span style="color:#616161">More Blocks</span> section, and create a block that looks like this:
 
 
<scratchblocks>
 
<scratchblocks>
print [] size () // category=custom
+
print [] size ():: custom
 
</scratchblocks>
 
</scratchblocks>
  
Now, a "Define" hat should appear. We will create it's script later.
+
Once the scratcher finishes, a "Define" hat should appear.
  
===Step 5===
+
Click the Data button, and create a [[variable]] that is open to all [[sprite]]s and named "letter on?".
Click the <span style="color:#616161">Data</span> button, and create a variable that is open to all sprites, not cloud and named "letter on?".
 
  
===Step 6===
+
In this step, <sb>print [] size ():: custom</sb> will be defined. Snap the following blocks underneath the define block so that the script looks like this:
Remember the define block that appeared earlier? We are now going to add some things to it. Snap the following blocks to it so the script looks like this:
 
  
 
<scratchblocks>
 
<scratchblocks>
define print [text] size (size)
+
define print [text] size (size::custom-arg)
 
set [letter on? v] to [1]
 
set [letter on? v] to [1]
 
repeat (length of (text))
 
repeat (length of (text))
switch costume to (letter (letter on?) of (text)
+
switch costume to (letter (letter on?) of (text))
 
stamp
 
stamp
change [letter on?] by (1)
+
change [letter on? v] by (1)
change x by (size)
+
change x by (size::custom-arg)
 
end
 
end
 
</scratchblocks>
 
</scratchblocks>
  
===Step 7===
 
 
Now, you have two different choices. You can choose whichever one you like better.
 
Now, you have two different choices. You can choose whichever one you like better.
  
====Step 7a====
 
 
One method of detecting which keys are pressed can be the 26-script way. It's like this:
 
One method of detecting which keys are pressed can be the 26-script way. It's like this:
  
Line 46: Line 37:
  
 
<scratchblocks>
 
<scratchblocks>
when key [a v] pressed
+
when [a v] key pressed
print [a] size (width of costumes) // category=custom
+
print [a] size (width of costumes):: custom
 
</scratchblocks>
 
</scratchblocks>
  
When using this method, you repeat the script 25 more times, but each with a different letter of the alphabet. First "a", then "b", and so on.
+
When using this method, you need to repeat the script 25 more times, but each with a different letter of the alphabet. First "a", then "b", and so on.
  
====Step 7b====
 
 
Another method of detecting which keys are pressed can be the 1-script way. First, create a script like this:
 
Another method of detecting which keys are pressed can be the 1-script way. First, create a script like this:
  
Line 58: Line 48:
 
when gf clicked
 
when gf clicked
 
forever
 
forever
if <key [a v] pressed>
+
if <key [a v] pressed?>:: control
print [a] size (width of costumes) // category=custom
+
print [a] size (width of costumes):: custom
 
else
 
else
 
+
...
 
end
 
end
 
</scratchblocks>
 
</scratchblocks>
  
Now, copy the "if else" part and stick it in the first "if else"'s "else". Change the "<key [a v] pressed" to "key [b v] pressed" and change the "print [a]..." to "print [b]...". Keep on doing this until you get to "y". The last part should look like this:
+
The next step is to copy the "if else" part and stick it in the first "if else"'s "else". Change the "<key [a v] pressed>" to "<key [b v] pressed>" and change the "print [a]..." to "print [b]...". Keep on doing this until you get to "y". This part is different, and should look like this:
  
 
<scratchblocks>
 
<scratchblocks>
 
...
 
...
if <key [y v] pressed>
+
if <key [y v] pressed?>:: control
print [y] size (width of costumes) // category=custom
+
print [y] size (width of costumes):: custom
 
else
 
else
if <key [z v] pressed>
+
if <key [z v] pressed?>:: control
print [z] size (width of costumes // category=custom
+
print [z] size (width of costumes):: custom
 
end
 
end
 
end
 
end
 
wait (delay time) secs
 
wait (delay time) secs
end forever block // category=control
 
 
</scratchblocks>
 
</scratchblocks>
  
==Conclusion==
+
Here is the completed script:
If you followed all of the above steps, you should now have a working typewriter!
+
<scratchblocks>
 +
when gf clicked
 +
forever
 +
if <key [a v] pressed?>:: control
 +
print [a] size (width of costumes):: custom
 +
else
 +
if <key [y v] pressed?>:: control
 +
print [y] size (width of costumes):: custom
 +
else
 +
if <key [z v] pressed?>:: control
 +
print [z] size (width of costumes):: custom
 +
end
 +
end
 +
wait (delay time) secs
 +
end
 +
 
 +
define print [text] size (size::custom-arg)
 +
set [letter on? v] to [1]
 +
repeat (length of (text))
 +
switch costume to (letter (letter on?) of (text)
 +
stamp
 +
change [letter on? v] by (1)
 +
change x by (size::custom-arg)
 +
end
 +
</scratchblocks>
  
 
[[Category:Other Tutorials]]
 
[[Category:Other Tutorials]]

Latest revision as of 06:28, 7 August 2018

A typewriter simulator is a simulation project where you can type notes, like in a word processor. This typewriter tutorial only requires simple scripting.

Creation

First, create a sprite. One can call it whatever the user wants to, but for this example, it will be called "Text".

Now, click the Costumes button above the block palette, and change the mode to vector. One will need to create a new costume with the letter "a", uppercase or lowercase. Name the costume "a".

Create 25 more costumes, but instead of making more "a"s, make one costume for each letter of the alphabet. The name of each costume should be the letter that the costume is.

Once the user has all of the costumes, create a custom block that looks like this:

print [] size ():: custom

Once the scratcher finishes, a "Define" hat should appear.

Click the Data button, and create a variable that is open to all sprites and named "letter on?".

In this step, print [] size ():: custom will be defined. Snap the following blocks underneath the define block so that the script looks like this:

define print [text] size (size::custom-arg)
set [letter on? v] to [1]
repeat (length of (text))
switch costume to (letter (letter on?) of (text))
stamp
change [letter on? v] by (1)
change x by (size::custom-arg)
end

Now, you have two different choices. You can choose whichever one you like better.

One method of detecting which keys are pressed can be the 26-script way. It's like this:

First, create a script like this:

when [a v] key pressed
print [a] size (width of costumes):: custom

When using this method, you need to repeat the script 25 more times, but each with a different letter of the alphabet. First "a", then "b", and so on.

Another method of detecting which keys are pressed can be the 1-script way. First, create a script like this:

when gf clicked
forever
if <key [a v] pressed?>:: control
print [a] size (width of costumes):: custom
else
...
end

The next step is to copy the "if else" part and stick it in the first "if else"'s "else". Change the "<key [a v] pressed>" to "<key [b v] pressed>" and change the "print [a]..." to "print [b]...". Keep on doing this until you get to "y". This part is different, and should look like this:

...
if <key [y v] pressed?>:: control
print [y] size (width of costumes):: custom
else
if <key [z v] pressed?>:: control
print [z] size (width of costumes):: custom
end
end
wait (delay time) secs

Here is the completed script:

when gf clicked
forever
if <key [a v] pressed?>:: control
print [a] size (width of costumes):: custom
else
if <key [y v] pressed?>:: control
print [y] size (width of costumes):: custom
else
if <key [z v] pressed?>:: control
print [z] size (width of costumes):: custom
end
end
wait (delay time) secs
end

define print [text] size (size::custom-arg)
set [letter on? v] to [1]
repeat (length of (text))
switch costume to (letter (letter on?) of (text)
stamp
change [letter on? v] by (1)
change x by (size::custom-arg)
end