Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » text editor engine
- the_sucram_dev
-
12 posts
text editor engine
I have been working on a written programing language and engine to go with it using scratch and it is going pretty well. but the list is pretty unappealing to write in so i have been trying to make a text editor engine that I can use to make it look far nicer anybody know how to do that
- PlatoHero_
-
500+ posts
text editor engine
Yes, it's actually possible to make a text editing engine in Scratch. You can't just use clones to display the letters, since that would put a limit of 300 characters to your code. So, you must stamp them instead. Now, there are a few questions I have to ask you before helping. Does using the list allow you to create functioning code? Do you want scrolling? Do you want I have been working on a written programing language and engine to go with it using scratch and it is going pretty well. but the list is pretty unappealing to write in so i have been trying to make a text editor engine that I can use to make it look far nicer anybody know how to do thathorizontal scrolling? What characters do you want to allow? What alternative to the backspace button do you want? Would you like to implement un-doing?
- the_sucram_dev
-
12 posts
text editor engine
yes the list can create functioning code and it will need vertical and horizontal scrolling but it cannot go farther left or up than the first location it will be like the vs code editor it needs to show all the letters and numbers possible along with ` + - = / and Maby more
- PlatoHero_
-
500+ posts
text editor engine
Alright. Since the list can create functioning code, we can use keyboard controls to manipulate the list and then display characters based on its contents. Firstly, we need some basic character recognition. To do that, we must specify what characters we should allow. The ASCII character set should be enough, since it includes these 100 keys: Enter, Space, !, “, #, $, %, &, ', (, ), *, comma, -, period, /, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?, @, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, \, square brackets, ^, _, `, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, {, |, }, ~, up arrow, down arrow, left arrow, right arrow. After putting all those keys in a list, which we shall call ”Keys", we can test if the key pressed at a specific instance corresponds to any of the keys, using this block: yes the list can create functioning code and it will need vertical and horizontal scrolling but it cannot go farther left or up than the first location it will be like the vs code editor it needs to show all the letters and numbers possible along with ` + - = / and Maby more
define check for keys
if <key (any v) pressed?> then
set [key index v] to (1)
repeat (100)
if <key (join (item (key index) of [Keys v]) ()) pressed?> then
type key (key index)
end
end
Then, we need a way to type these characters. To do that, we implement these blocks:
define split line (line) at (cursor)
delete all of [line v]
set [char index v] to (1)
repeat (length of (item (line) of [Code v]))
add (letter (char index) of (item (line) of [Code v])) to [list v]
end
set [first part v] to ()
set [char index v] to (1)
repeat (cursor)
set [first part v] to (join (first part) (item (char index) of [line v]))
change [char index v] by (1)
end
set [second part v] to ()
repeat ((length of [list v]) - (cursor))
set [second part v] to (join (second part) (item (char index) of [line v]))
change [char index v] by (1)
end
define type key (key)
if <(key) = (1)> then
split line (line) at (cursor)
replace item (line) of [code v] with (first part)
change [line v] by (1)
set [cursor v] to (0)
insert (second part) at (line) of [Code v]
else
if <(key) = (97)> then
if <not <(line) = (1)>> then
change [line v] by (-1)
if <(cursor) > (length of (item (line) of [Code v])) > then
set [cursor v] to (length of (item (line) of [Code v]))
end
end
else
if <(key) = (98)> then
if <not <(line) = (length of [Code v])>> then
change [line v] by (1)
if <(cursor) > (length of (item (line) of [Code v])) > then
set [cursor v] to (length of (item (line) of [Code v]))
end
end
else
if <(key) = (99)> then
if <(cursor) = (0)> then
if <not <(line) = (0)>> then
change [line v] by (-1)
set [cursor v] to (length of (item (line) of [Code v]))
end
else
change [cursor v] by (-1)
end
else
if <(key) = (100)> then
if <(cursor) = (length of (item (line) of [Code v]))> then
if <not <(line) = (length of [Code v])>> then
change [line v] by (1)
set [cursor v] to (0)
end
else
change [cursor v] by (1)
end
else
split line (line) at (cursor)
replace item (line) of [Code v] with (join (first part) (join (item (key) of [Keys v]) (second part)))
end
end
end
end
end
And finally, a looping statement to put it all together.
when green flag clicked
set [line v] to (0)
set [cursor v] to (0)
forever
check for keys
end
Now, if you are comfortable with rendering tilled planes with stamping, you should be able to handle rendering the characters of the list similarly. If you are not, or you notice any bugs in my code, let me know.
Edit: I noticed a bug with my code and fixed it.
Last edited by PlatoHero_ (Feb. 16, 2025 22:29:25)
- the_sucram_dev
-
12 posts
text editor engine
thanks I already have a renderer so this is very useful
- the_sucram_dev
-
12 posts
text editor engine
we got a problem it will type both the capital and not capital versions each time
- PlatoHero_
-
500+ posts
text editor engine
I didn't expect this issue. Actually, due to the case insensivity of Scratch, the only solution available would be storing the capital and non-capital versions of the 26 letters in costume names. Alternatively, you could make your programming language all-caps or no-caps. What would you prefer? we got a problem it will type both the capital and not capital versions each time
Last edited by PlatoHero_ (Yesterday 07:48:31)
- Discussion Forums
- » Help with Scripts
-
» text editor engine