Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Obscure - The brand-new, Turing-Complete, easy to use programming language
- davidtheplatform
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
I found a bug with nesting if/while statements:
while some_condition
if some_other_condition
# anything
end # this line ends the while and the if, when it should just end the if
end # invalid, since the while already ended
- i_eat_coffee
- Scratcher
1000+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
Fixed, and also added functions with this update I found a bug with nesting if/while statements:while some_condition
if some_other_condition
# anything
end # this line ends the while and the if, when it should just end the if
end # invalid, since the while already ended
lmk if everything works correctly i only tested some nesting errors with the new function blocks
- davidtheplatform
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
One more thing: can you make replace accept a variable for the index? Ie. replace {i} of array as some_value
- 50_scratch_tabs
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
Oh did it not? One more thing: can you make replace accept a variable for the index? Ie. replace {i} of array as some_value
- 50_scratch_tabs
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
It has a confirmation box for untrusted domains…but still…maybe instead of asking it could run in some sort of sandbox? I'll look into that. but people r gonna get ip grabbed or token grabbed when i add accounts ..?
- i_eat_coffee
- Scratcher
1000+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
done One more thing: can you make replace accept a variable for the index? Ie. replace {i} of array as some_value
- 50_scratch_tabs
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
Could you please add length of string/list?
Edit, didn't read the docs thoroughly enough.
Edit, didn't read the docs thoroughly enough.
Last edited by 50_scratch_tabs (Sept. 7, 2024 15:25:49)
- 50_scratch_tabs
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
Might be a bit of a task, but could you please add catching exceptions? Maybe something like:
then when an error occurs myfunction is called, and a variable (maybe {errortext} or something) is set to the exception's text. Also maybe implement
to unregister myfunction as an error handler. Or maybe something like:
One more thing: could you please see if you can disable spellcheck or the red underline for the code editor?
Also, I feel like you should be able to call functions that set a variable inline, like this:
or something, where using run: takes a function that normally has "do something as variable" and just insert the result there?
Another idea: delete <item> of array
I know I have a ton of requests, they are coming to me as I'm coding BrainF in Obscure.
catch myfunction
then when an error occurs myfunction is called, and a variable (maybe {errortext} or something) is set to the exception's text. Also maybe implement
uncatch myfunction
call mybuggyfunction catch myerrorhandler
One more thing: could you please see if you can disable spellcheck or the red underline for the code editor?
Also, I feel like you should be able to call functions that set a variable inline, like this:
out {run:add 3 {myvar}}
or something, where using run: takes a function that normally has "do something as variable" and just insert the result there?
Another idea: delete <item> of array
I know I have a ton of requests, they are coming to me as I'm coding BrainF in Obscure.
Last edited by 50_scratch_tabs (Sept. 7, 2024 15:35:54)
- 50_scratch_tabs
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
Could you please make errors print the line number?
Also, could errors please not clear the console? So hard to debug!
Also, could errors please not clear the console? So hard to debug!
Last edited by 50_scratch_tabs (Sept. 7, 2024 15:47:44)
- i_eat_coffee
- Scratcher
1000+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
ill just put this on github and make some pull requests whenver u need something ok thx Might be a bit of a task, but could you please add catching exceptions? Maybe something like:catch myfunction
then when an error occurs myfunction is called, and a variable (maybe {errortext} or something) is set to the exception's text. Also maybe implementto unregister myfunction as an error handler. Or maybe something like:uncatch myfunctioncall mybuggyfunction catch myerrorhandler
One more thing: could you please see if you can disable spellcheck or the red underline for the code editor?
Also, I feel like you should be able to call functions that set a variable inline, like this:out {run:add 3 {myvar}}
or something, where using run: takes a function that normally has "do something as variable" and just insert the result there?
Another idea: delete <item> of array
I know I have a ton of requests, they are coming to me as I'm coding BrainF in Obscure.
- 50_scratch_tabs
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
(#233)
ill just put this on github and make some pull requests whenver u need something ok thx
really sorry i don't have github
might just make a remix, but then again I don't have glitch either…local devserver it is!
Last edited by 50_scratch_tabs (Sept. 7, 2024 15:56:30)
- ThisIsTemp1
- Scratcher
1000+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
out Hello and Welcome to Uno!
delay 2
out There are 4 players, and you all will receive 7 random cards. Please wait.
array Red1 Red2 Red3 Red4 Red5 Red6 Red7 Red8 Red9 RedReverse RedSkip RedDraw2 Blue1 Blue2 Blue3 Blue4 Blue5 Blue6 Blue7 Blue8 Blue9 BlueReverse BlueSkip BlueDraw2 Yellow1 Yellow2 Yellow3 Yellow4 Yellow5 Yellow6 Yellow7 Yellow8 Yellow9 YellowReverse YellowSkip YellowDraw2 Green1 Green2 Green3 Green4 Green5 Green6 Green7 Green8 Green9 GreenReverse GreenSkip GreenDraw2 Wild Draw4 as TypesofCards
set i to 0
random 1 50 as chooser
array {TypesofCards:chooser} as PlayerCards
while i < 6
random 1 50 as chooser
unshift PlayerCards {TypesofCards:chooser}
add {i} 1 as i
end
set i to 0
random 1 50 as chooser
array {TypesofCards:chooser} as Bot1Cards
while i < 6
random 1 50 as chooser
unshift Bot1Cards {TypesofCards:chooser}
add {i} 1 as i
end
set i to 0
random 1 50 as chooser
array {TypesofCards:chooser} as Bot2Cards
while i < 6
random 1 50 as chooser
unshift Bot2Cards {TypesofCards:chooser}
add {i} 1 as i
end
set i to 0
random 1 50 as chooser
array {TypesofCards:chooser} as Bot3Cards
while i < 6
random 1 50 as chooser
unshift Bot3Cards {TypesofCards:chooser}
add {i} 1 as i
end
out {PlayerCards:1} and {PlayerCards:2} and {PlayerCards:3} and {PlayerCards:4} and {PlayerCards:5} and {PlayerCards:6}
The output is only the first one and 5 ands.
It only supports the first item in a list to print.
- i_eat_coffee
- Scratcher
1000+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
-snip-
The output is only the first one and 5 ands.
It only supports the first item in a list to print.
arrays.PlayerCards just has one item, it's a bug with your code
- 50_scratch_tabs
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
Alright, my entry for the contest is done! Here's the code: (comments added and indention corrected by ChatGPT)
It works better on Chrome but still works on Firefox, due to the way prompt boxes are shown. On Firefox you will just have to read the console a bit smaller darker.
It works better on Chrome but still works on Firefox, due to the way prompt boxes are shown. On Firefox you will just have to read the console a bit smaller darker.
# Workaround to get just a space in a variable
set space to . .
set space to {letter 2:space}
# Define a function to output the board
function outboard
clear
# Output the first row of the board
out {status}
out {space}
out {space}
out {board:1} | {board:2} | {board:3}
out --+---+--
# Output the second row of the board
out {board:4} | {board:5} | {board:6}
out --+---+--
# Output the third row of the board
out {board:7} | {board:8} | {board:9}
end
# Define a function to handle a win scenario
function win
# Call the function to output the board, with the winner message
set status to {turn} wins!
call outboard
# End the game loop
set stillrun to 0
end
# Initialize the game board
array 1 2 3 4 5 6 7 8 9 as board
# Set the initial turn to X
set turn to X
# Set the game running flag
set stillrun to 1
# Main game loop
while {stillrun} = 1
# Set the top line of the rendered board
set status to Player {turn}, make your move.
# Call the function to output the board
call outboard
# Delay to allow for visual updates
delay 0.1
# Player 1's turn
if {turn} = X
ask Player 1 (X) pick? as pick
end
# Player 2's turn
if {turn} = O
ask Player 2 (O) pick? as pick
end
# Check if the picked cell is empty
multiply {board:pick} 0 as isboard
if {isboard} = 0
# Place the turn's mark in the picked cell
replace {pick} of board as {turn}
end
# Check for a winning condition
# Check rows
if {board:1} = {turn} and {board:2} = {turn} and {board:3} = {turn}
call win
end
if {board:4} = {turn} and {board:5} = {turn} and {board:6} = {turn}
call win
end
if {board:7} = {turn} and {board:8} = {turn} and {board:9} = {turn}
call win
end
# Check columns
if {board:1} = {turn} and {board:4} = {turn} and {board:7} = {turn}
call win
end
if {board:2} = {turn} and {board:5} = {turn} and {board:8} = {turn}
call win
end
if {board:3} = {turn} and {board:6} = {turn} and {board:9} = {turn}
call win
end
# Check diagonals
if {board:1} = {turn} and {board:5} = {turn} and {board:9} = {turn}
call win
end
if {board:3} = {turn} and {board:5} = {turn} and {board:7} = {turn}
call win
end
# Change turn if the board was updated
if {isboard} = 0
# Save the old turn value
set oldturn to {turn}
# Switch turn between X and O
if {oldturn} = X
set turn to O
end
if {oldturn} = O
set turn to X
end
end
end
Last edited by 50_scratch_tabs (Sept. 10, 2024 01:52:33)
- davidtheplatform
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
I found a really weird bug…
If you try to check if a certain letter in a string is a bracket, it always thinks it isn't.
Expected output is “a b”, while it just outputs “b”. This doesn't happen with letters.
For some reason this only happens when you use “{letter a:b}” directly in the comparison, using an intermediate variable works as expected:
Here the output is “c”.
Somewhat related bug, if you set a variable to a letter of another variable, you can't access the last character. Basically “set foo to ab; set bar to {letter 2:foo}” fails when it should set bar to “b”.
If you try to check if a certain letter in a string is a bracket, it always thinks it isn't.
set a to [
set b to [
if {letter 1:a} = [
out a
end
if {b} = [
out b
end
For some reason this only happens when you use “{letter a:b}” directly in the comparison, using an intermediate variable works as expected:
set b to {letter 1:a}
if {b} = [
out c
end
Somewhat related bug, if you set a variable to a letter of another variable, you can't access the last character. Basically “set foo to ab; set bar to {letter 2:foo}” fails when it should set bar to “b”.
Last edited by davidtheplatform (Sept. 8, 2024 02:22:18)
- davidtheplatform
- Scratcher
500+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
My submission to the contest: A BrainF interpreter!
It supports all of BF, including input*, neverending/interacive programs, and performance counters.
It's really slow, running at about 1500 cycles/second.
Here's the code:
If you don't know what BF is, its an esoteric language designed to be as simple as possible. “BF” is an abbreviation of a word not allowed on scratch. There are only 8 instructions:
Here's some example programs:
Hello world
Powers of two
Sierpinski triangle (slow - takes around 15 minutes to finish)
A quine (also slow - I don't know if it actually works)
Another quine (this one works)
Fibonacci sequence
*input is kind of weird right now, I plan on making it better soon
It supports all of BF, including input*, neverending/interacive programs, and performance counters.
It's really slow, running at about 1500 cycles/second.
Here's the code:
# BF interpreter
# (c) 2024 davidtheplatform
out Initializing...
date timestamp as init_time
delay 0.1
array > > ⠀ ! " # $ % & ' ( ) * + , - . / 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 [ \ ] ^ _ ` 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 { | } ~ ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ as characters
set bracket_level to 0
function jump_open
set current_letter to {letter ip:program}
set jump_stop to 0
set bracket_level to 0
while {jump_stop} = 0
if {current_letter} = ]
add {bracket_level} 1 as bracket_level
end
if {current_letter} = [
add {bracket_level} -1 as bracket_level
end
add {ip} -1 as ip
set current_letter to {letter ip:program}
if {bracket_level} = 0
set jump_stop to 1
end
end
add {ip} 1 as ip
end
function jump_close
set current_letter to {letter ip:program}
set jump_stop to 0
set bracket_level to 0
while {jump_stop} = 0
if {current_letter} = [
add {bracket_level} 1 as bracket_level
end
if {current_letter} = ]
add {bracket_level} -1 as bracket_level
end
add {ip} 1 as ip
set current_letter to {letter ip:program}
if {bracket_level} = 0
set jump_stop to 1
end
end
add {ip} -1 as ip
end
function input_to_ascii
set c to 1
while {c} < 256
if {characters:c} = {input}
replace {dp} of memory as {c}
set c to 256
end
add {c} 1 as c
end
end
function print_memory
outl [
set count to 0
while {count} < {length:memory}
add {count} 1 as count
outl {memory:count},
end
out ]
end
# data pointer
set dp to 1
# instruction pointer
set ip to 1
# initialize memory
array 0 as memory
set counter to 0
while {counter} < 29999
push memory 0
add {counter} 1 as counter
end
date timestamp as init_end_time
# get program
ask Enter Program as program
# add a character to the end because of a bug
set program to {program}~
set cycles to 0
set program_ended to 0
date timestamp as start_time
while {program_ended} = 0
set instruction to {letter ip:program}
add {cycles} 1 as cycles
# out ({cycles}) {ip}: {instruction}
if {instruction} = +
set temp to {memory:dp}
add {temp} 1 as temp
replace {dp} of memory as {temp}
if {memory:dp} = 256
replace {dp} of memory as 0
end
end
if {instruction} = -
set temp to {memory:dp}
add {temp} -1 as temp
replace {dp} of memory as {temp}
if {memory:dp} = -1
replace {dp} of memory as 255
end
end
if {instruction} = <
add {dp} -1 as dp
end
if {instruction} = >
add {dp} 1 as dp
end
if {instruction} = [
if {memory:dp} = 0
call jump_close
end
end
if {instruction} = ]
if {memory:dp} != 0
call jump_open
end
end
if {instruction} = .
set char to {memory:dp}
set is_10 to 0
set is_13 to 0
if {char} != 10
set is_10 to 1
end
if {char} != 13
set is_13 to 1
end
multiply {is_10} {is_13} as not_10_13
if {not_10_13} = 0
out ⠀
end
if {not_10_13} = 1
outl {characters:char}
end
# add a delay so the text shows up
delay 0.01
end
if {instruction} = ,
ask Program wants input (a single char = that char, anything else = EOF, blank input will cause a crash) as input
call input_to_ascii
end
# add a small delay every once in a while to keep the page from crashing
modulus {cycles} 1000 as should_delay
if {should_delay} = 0
delay 0.01
end
# debugging
if {instruction} = #
out --- Debug ---
call print_memory
out dp: {dp}
out ip: {ip}
out -------------
end
add {ip} 1 as ip
if {ip} = {length:program}
set program_ended to 1
end
end
date timestamp as end_time
subtract {init_end_time} {init_time} as init_duration
subtract {end_time} {start_time} as run_duration
divide {cycles} {run_duration} as cycles_per_ms
multiply {cycles_per_ms} 1000 as cycles_per_s
out ⠀
out ⠀
out Program finished in {run_duration}ms; {cycles} cycles; {cycles_per_s} cycles per second; init time {init_duration}ms
If you don't know what BF is, its an esoteric language designed to be as simple as possible. “BF” is an abbreviation of a word not allowed on scratch. There are only 8 instructions:
> Increment the data pointer by one (to point to the next cell to the right).
< Decrement the data pointer by one (to point to the next cell to the left).
+ Increment the byte at the data pointer by one.
- Decrement the byte at the data pointer by one.
. Output the byte at the data pointer.
, Accept one byte of input, storing its value in the byte at the data pointer.
[ If the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command.
] If the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command.
Here's some example programs:
Hello world
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
>++++++++++>>+<+[[+++++[>++++++++<-]>.<++++++[>--------<-]+<<]>.>[->[<++>-[<++>-[<++>-[<++>-[<-------->>[-]++<-[<++>-]]]]]]<[>+<-]+>>]<<]
++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<]>.>+[>>]>+]
->++>+++>+>+>+++>>>>>>>>>>>>>>>>>>>>+>+>++>+++>++>>+++>+>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>+>+>>+++>>+++>>>>>+++>+>>>>>>>>>++>+++>+++>+>>+++>>>+++>+>++>+++>>>+>+>
++>+++>+>+>>+++>>>>>>>+>+>>>+>+>++>+++>+++>+>>+++>>>+++>+>++>+++>++>>+>+>++>+++>
+>+>>+++>>>>>+++>+>>>>>++>+++>+++>+>>+++>>>+++>+>+++>+>>+++>>+++>>++[[>>+[>]++>+
+[<]<-]>+[>]<+<+++[<]<+]>+[>]++++>++[[<++++++++++++++++>-]<+++++++++.<]
>+++++>+++>+++>+++++>+++>+++>+++++>++++++>+>++>+++>++++>++++>+++>+++>+++++>+>+
>++++>+++++++>+>+++++>+>+>+++++>++++++>+++>+++>++>+>+>++++>++++++>++++>++++>+++
>+++++>+++>+++>++++>++>+>+>+>+>++>++>++>+>+>++>+>+>++++++>++++++>+>+>++++++
>++++++>+>+>+>+++++>++++++>+>+++++>+++>+++>++++>++>+>+>++>+>+>++>++>+>+>++>++>+
>+>+>+>++>+>+>+>++++>++>++>+>+++++>++++++>+++>+++>+++>+++>+++>+++>++>+>+>+>+>++
>+>+>++++>+++>+++>+++>+++++>+>+++++>++++++>+>+>+>++>+++>+++>+++++++>+++>++++>+
>++>+>+++++++>++++++>+>+++++>++++++>+++>+++>++>++>++>++>++>++>+>++>++>++>++>++
>++>++>++>++>+>++++>++>++>++>++>++>++>++>+++++>++++++>++++>+++>+++++>++++++>++++
>+++>+++>++++>+>+>+>+>+++++>+++>+++++>++++++>+++>+++>+++>++>+>+>+>++++>++++
[[>>>+<<<-]<]>>>>[<<[-]<[-]+++++++[>+++++++++>++++++<<-]>-.>+>[<.<<+>>>-]>]
<<<[>>+>>>>+<<<<<<-]>++[>>>+>>>>++>>++>>+>>+[<<]>-]>>>-->>-->>+>>+++>>>>+[<<]
<[[-[>>+<<-]>>]>.[>>]<<[[<+>-]<<]<<]
>++++++++++>+>+[[+++++[>++++++++<-]>.<++++++[>--------<-]+<<<]>.>>[[-]<[>+<-]>>[<<+>+>-]<[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>[-]>+>+<<<-[>+<-]]]]]]]]]]]+>>>]<<<]
*input is kind of weird right now, I plan on making it better soon
- Redstone1080
- Scratcher
1000+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
would be funny if i wrote an obscure interpreter in zig
probably wouldnt be that hard
probably wouldnt be that hard
Last edited by Redstone1080 (Sept. 8, 2024 12:56:35)
- endyourenite
- Scratcher
100+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
heres a thing to know:
When I see light mode, It kinda kill my eyes.
When I see light mode, It kinda kill my eyes.
- endyourenite
- Scratcher
100+ posts
Obscure - The brand-new, Turing-Complete, easy to use programming language
Can I join? (this is for contest)
This Is A script of the calculator. What you do is type in the 1st digit (numbers only) (9__), then, you type in a operator, (Add/Subtract/Multipy/Divide) (9+_), then the 2nd digit (numbers only) (9+2). Since I done 9+2, it will output ‘9 + 2 = 11’. This Has 36 lines of code (I think) and its simple . That is all I have to say.
clear
ask insert the first digit (number only) as 1stdigit
ask Divide, Multiply, Add or Subtract? as DMAS
ask insert the second digit (number only) as 2nddigit
if {DMAS} = Multiply
multiply {1stdigit} {2nddigit} as answerM
out {1stdigit} x {2nddigit} = {answerM}
end
if {DMAS} = Divide
divide {1stdigit} {2nddigit} as answerD
out {1stdigit} ÷ {2nddigit} = {answerD}
end
if {DMAS} = Add
add {1stdigit} {2nddigit} as AnswerA
out {1stdigit} + {2nddigit} = {AnswerA}
end
if {DMAS} = Subtract
subtract {1stdigit} {2nddigit} as AnswerS
out {1stdigit} - {2nddigit} = {AnswerS}
end
if {DMAS} = multiply
multiply {1stdigit} {2nddigit} as answerM
out {1stdigit} x {2nddigit} = {answerM}
end
if {DMAS} = divide
divide {1stdigit} {2nddigit} as answerD
out {1stdigit} ÷ {2nddigit} = {answerD}
end
if {DMAS} = add
add {1stdigit} {2nddigit} as AnswerA
out {1stdigit} + {2nddigit} = {AnswerA}
end
if {DMAS} = subtract
subtract {1stdigit} {2nddigit} as AnswerS
out {1stdigit} - {2nddigit} = {AnswerS}
end
Last edited by endyourenite (Sept. 8, 2024 14:42:05)
- i_eat_coffee
- Scratcher
1000+ posts