Discuss Scratch

i_eat_coffee
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

I updated the sample projects a bit

DifferentDance8
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

i_eat_coffee wrote:

I updated the sample projects a bit

I think the original version of the song is allowed. I made a topic in QaS about it as a programming project and Za said it was fine so
Don't have the link on me though
i_eat_coffee
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

i could use setTimeout() instead of while() for the ‘while’ block so it doesnt crash but then idk how to add a function to stop it if it runs infinitely
i_eat_coffee
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

I MADE THE WORLD'S FIRST NEURAL NETWORK IN OBSCURE!!!!!!11111111!!!1!1!111
TRY IT OUT:
out A perceptron is the simplest form of a Neural Network
out An input is either 0 (FALSE) or 1 (TRUE)
out A weight is how important an input is, from 0.1 to 1.0 (e.g. 0.4)

delay 5

ask Input 1 as i1
ask Weight 1 as w1

ask Input 2 as i2
ask Weight 2 as w2

ask Input 3 as i3
ask Weight 3 as w3

set thresh to 1.5

multiply {i1} {w1} as i1
multiply {i2} {w2} as i2
multiply {i3} {w3} as i3

add {i1} {i2} as result
add {result} {i3} as result

set res to 1
if {result} < {thresh}
set res to 0
end

out {res}

Last edited by i_eat_coffee (Sept. 4, 2024 12:07:49)

ZuzuBestGirl
Scratcher
4 posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

Hi! ^w^
Is there a way to do an infinite loop in the program? I tried to make a loop with a delay so that it doesn't crash, but it crashes anyway! Any way you could make a loop that doesn't crash the page? :3

Last edited by ZuzuBestGirl (Sept. 4, 2024 12:36:30)

i_eat_coffee
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

ZuzuBestGirl wrote:

Hi! ^w^
Is there a way to do an infinite loop in the program? I tried to make a loop with a delay so that it doesn't crash, but it crashes anyway! Any way you could make a loop that doesn't crash the page? :3
yep, for that i will actually have to modify the current <while-loop> system in the interpreter, but it'd be ready + lots of other bug fixes before the end of the contest
ZuzuBestGirl
Scratcher
4 posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

I think I found the problem, the delay isn't working because the while loop is trying to run the delay without a screen refresh, its pretty much acting as if you were to make a custom block in scratch with a forever loop without screen refresh! :3
Also sorry for not quoting, I almost never use forums >_<

Last edited by ZuzuBestGirl (Sept. 4, 2024 13:53:06)

i_eat_coffee
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

ZuzuBestGirl wrote:

I think I found the problem, the delay isn't working because the while loop is trying to run the delay without a screen refresh, its pretty much acting as if you were to make a custom block in scratch with a forever loop without screen refresh! :3
Also sorry for not quoting, I almost never use forums >_<
a while() loop is basically always gonna crash if the condition will never be false
ZuzuBestGirl
Scratcher
4 posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

i_eat_coffee wrote:

ZuzuBestGirl wrote:

I think I found the problem, the delay isn't working because the while loop is trying to run the delay without a screen refresh, its pretty much acting as if you were to make a custom block in scratch with a forever loop without screen refresh! :3
Also sorry for not quoting, I almost never use forums >_<
a while() loop is basically always gonna crash if the condition will never be false
A while loop with no false condition is basically a forever loop, but because of it trying to do every loop at once, it crashes. I was just trying to make a forever loop with a slight delay like in scratch "-w-
A-MARIO-PLAYER
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

uhh variable definitions dont work anymore

it says invalid variable definition iirc
i_eat_coffee
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

A-MARIO-PLAYER wrote:

uhh variable definitions dont work anymore

it says invalid variable definition iirc
works fine for me?

out Hello, world!

#variable definition:
set nth to first
out This is my {nth} project :)
mybearworld
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

ZuzuBestGirl wrote:

(#189)
A while loop with no false condition is basically a forever loop, but because of it trying to do every loop at once, it crashes. I was just trying to make a forever loop with a slight delay like in scratch "-w-
It's not really trying to run everything at once, it's just that because of how JavaScript in browsers works, it's waiting for it to finish before it can start doing other things, but it never does with a forever loop. There are ways to mitigate this though
i_eat_coffee
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

PkmnQ decided to make a quine, and it's a bit long………………….
set s to a a
array out sp set sp s sp to sp a sp nl a outl sp nl array reverse sp array sp quine sp as sp nl quine while sp { quine:304} sp != sp 0 nl 0 outl sp {letter sp 2:s}{ nl quine:304} unshift sp quine sp 0 nl 0 nl end out sp {letter sp 2:s}as sp nl quine set sp n l sp to sp nl no set sp s p sp to sp nl no while sp { quine:609} sp != sp 0 nl 0 set sp j sp to sp { nl quine:609} while sp { j} sp = sp n nl l set sp n l sp to sp nl yes set sp j sp to sp nl j nl end while sp { j} sp = sp s nl p set sp s p sp to sp nl yes set sp j sp to sp nl j nl end set sp j sp to sp { nl quine:609} while sp { j} sp != sp n l sp and sp { j} sp != sp s nl p while sp { sp} sp = sp nl yes set sp j sp to sp {letter sp 2:s}{ nl j} set sp s p sp to sp nl no nl end while sp { nl} sp = sp nl yes out sp { nl j} set sp n l sp to sp nl nah nl end while sp { nl} sp = sp nl no outl sp { nl j} set sp n l sp to sp nl nah nl end while sp { nl} sp = sp nl nah set sp n l sp to sp nl no nl end set sp j sp to sp n nl l nl end unshift sp quine sp 0 nl 0 end as quine
out set s to a a
outl array
reverse array quine as quine
while {quine:304} != 00
outl {letter 2:s}{quine:304}
unshift quine 00
end
out {letter 2:s}as quine
set nl to no
set sp to no
while {quine:609} != 00
set j to {quine:609}
while {j} = nl
set nl to yes
set j to j
end
while {j} = sp
set sp to yes
set j to j
end
set j to {quine:609}
while {j} != nl and {j} != sp
while {sp} = yes
set j to {letter 2:s}{j}
set sp to no
end
while {nl} = yes
out {j}
set nl to nah
end
while {nl} = no
outl {j}
set nl to nah
end
while {nl} = nah
set nl to no
end
set j to nl
end
unshift quine 00
end
but it actually works
the very first quine in Obscure???
woww!!111!!
i_eat_coffee
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language



the design has been updated, dark mode is coming after the contest ends
50_scratch_tabs
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

i_eat_coffee wrote:

(#179)
pls test it and lmk
Sorry can't really test right now. I'm on mobile today and my project is on PC, in addition to the fact that typing code on mobile is annoying.
BigNate469
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

50_scratch_tabs wrote:

typing code on mobile is annoying.
I second that
and it is currently the only reason that I haven't tried to write anything in Obscure yet
ThisIsTemp1
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

How do you print a list?
blubby4
Scratcher
100+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

Here's my interpreter if anyone's interested. It has while loops that don't freeze the page

There are some things to note:

Variable assignment:
Set <name> to <value>

Addition:
Set <var> to add <value1> <value2> <value3> … <valueN>

You can also write shortened version:
Set <var> to sub <value1> <value2> <value3> … <valueN>
Set <var> to subtract <value1> <value2> <value3> … <valueN>


Anyway, here's the html (don't ask what happened to the indentation, I don't know):
<!DOCTYPE HTML>
<html lang=en>
<head>
<title>Obscure</title>
</head>
<body>
<textarea id="input" style="position: absolute;top: 25%;width: 47%;height: 50%;border: 1px solid black;font-family: monospace;resize: none;left: 2%;"></textarea>
<textarea id="output" style="position: absolute;top: 25%;width: 47%;height: 50%;border: 1px solid black;font-family: monospace;resize: none;right: 2%;"></textarea>
<button id="run" style="position: absolute;bottom: 75%;margin-bottom: 5px;width: 50px;right: 51%;">run</div>
<button id="stop" style="position: absolute;bottom: 75%;margin-bottom: 5px;width: 50px;left: 51%;">stop</div>

<script>
const input = document.getElementById("input")
const output = document.getElementById("output")
const runButton = document.getElementById("run")
const stopButton = document.getElementById("stop")

output.value = ""


output.addEventListener("keydown", (e) => {
e.preventDefault()
})
input.addEventListener("keydown", (e) => {
const start = e.target.selectionStart
const end = e.target.selectionEnd

if (e.keyCode == 9) { // Tab
e.preventDefault()

let i = start
while (i <= end) {
if (i == start || input.value[i - 1] == "\n") {
input.value = input.value.slice(0, i) + " " + input.value.slice(i)
if (start == end) {
input.selectionStart = start + 2
input.selectionEnd = end + 2
}
}

i++
}
}
if (e.keyCode == 8) { // Backspace
if (start == end) {
if (input.value.slice(start - 2, start) == " ") {
e.preventDefault()

input.value = input.value.slice(0, start - 2) + input.value.slice(start)

input.selectionStart = start - 2
input.selectionEnd = start - 2
}
}
}
})
runButton.addEventListener("click", (e) => {
output.value = ""
runCode(input.value)
})
stopButton.addEventListener("click", (e) => {
stop = true
})


function out(msg) {
output.value += msg
output.selectionStart = output.value.length
output.selectionEnd = output.value.length
}
function error(msg, removePrefix) {
if (removePrefix == true) {
out(msg + "\n")
} else {
out("ERROR: " + msg + "\n")
}
}



/* --- Interpreter --- */


let stop = false

function runCode(code) {
stop = false
evaluateBlock(code, {}, -1)
}


function evaluateBlock(block, variables, PC) {
if (stop) {
return
}

try {
const lines = block.split("\n")

let skipDepth = 0
let skipDir = 1

let safety = 0
while (PC < lines.length - 1) {
safety++
if (safety > 100) {
setTimeout(evaluateBlock, 10, block, variables, PC)
return
}

PC += skipDir

let line = lines[PC]
if (line.replaceAll(" ", "") == "") {
continue
}

line = preprocessExpression(line, variables, PC + 1)
if (line === false) {
return false
}

const args = line.split(" ").filter((arg) => arg != "")

if (skipDepth > 0) {
switch (args[0]) {
default: continue

case "if":
case "while": {
skipDepth += skipDir
if (skipDepth <= 0) {
skipDir = 1
PC--
if (args[0] == "if") {
skipDepth = 1
}
}
continue
}

case "end": {
skipDepth -= skipDir
continue
}
}
}

const result = evaluateLine(args, variables, PC + 1)
if (!result) {
return false
}
if (result == true) {

} else if (result == "skipForward") {
skipDepth = 1
} else if (result == "skipBackward") {
skipDepth = 1
skipDir = -1
} else if (result.slice(0, 5) == "wait_") {
setTimeout(evaluateBlock, result.slice(5), block, variables, PC)
return
}
}
} catch(e) {
error("An interpreter (JS) error occurred. This should not happen!")
error("Please notify blubby4 at", true)
error("https://scratch.mit.edu/discuss/topic/777854/", true)
error("And paste the below:", true)
error("Code:\n", true)
error(input.value, true)
error("\nError:", true)
error(e.toString(), true)
error(`Line: ${e.lineNumber} (FF only)`, true)
}
}


function preprocessExpression(exp, vars, lineNum) {
let i = -1
let depth = 0
let braceStart = 0

while (i < exp.length) {
i++

const chr = exp[i]
if (chr == "{") {
if (depth == 0) {
braceStart = i
}
depth++
}
if (chr == "}") {
depth--
if (depth == 0) {
const rawName = exp.slice(braceStart + 1, i)
const varName = preprocessExpression(rawName, vars, lineNum)

const varValue = vars[varName]
if (varValue == undefined) {
error(`Undefined variable "${varName}": line ${lineNum}`)
return false
}

exp = exp.slice(0, braceStart) + varValue + exp.slice(i + 1)
i -= i - braceStart + 1
}
if (depth < 0) {
error(`Unexpected closing brace: line ${lineNum}, column ${i + 1}`)
return false
}
}
}

if (depth > 0) {
error(`Unclosed brace: line ${lineNum}, column ${braceStart + 1}`)
return false
}

return exp
}


function evaluateLine(args, vars, lineNum) {
switch (args[0]) {
case "out":
case "outl": {
const msg = args.slice(1).join(" ")
if (args[0] == "outl") { // Out has newline, outl does not
out(msg)
} else {
out(msg + "\n")
}

break
}


case "set": {
if (args[2] != "to") {
error(`Expected "to", got "${args[2]}": line ${lineNum}`)
return false
}

const varName = args[1]
let value = ""
switch (args[3]) {
default: {
value = args.slice(3).join(" ")

break
}

case "divide": case "div":
case "multiply": case "mult":
case "subtract": case "sub":
case "add": {
value = 0
for (let i = 4; i < args.length; i++) {
const varValue = Number(args[i])
if(isNaN(varValue)) {
error(`Expected number, got "${args[i]}" instead: line ${lineNum}, operand ${i - 3}`)
return false
}

switch ("_" + args[3]) {
case "_divide": case "_div": {
if (i == 4) {
value = varValue
} else {
value /= varValue
}
break
}
case "_multiply": case "_mult": {
value *= varValue
break
}
case "_subtract": case "_sub": {
if (i == 4) {
value = varValue
} else {
value -= varValue
}
break
}
case "_add": {
value += varValue
break
}
}
}

break
}

case "ask": {
value = prompt(args.slice(4).join(" ")) ?? ""

break
}

case "date": {
const date = new Date()

switch (args[4]) {
default: {
error(`Date is of invalid type "${args[4]}": line ${lineNum}`)
return false
}

case "year": {
value = date.getFullYear()
break
}
case "month": {
value = date.getMonth() + 1
break
}
case "date": {
value = date.getDate()
break
}
case "hour": {
value = date.getHours()
break
}
case "minute": {
value = date.getMinutes()
break
}
case "second": {
value = date.getSeconds()
break
}
case "timestamp": {
value = date.getTime()
break
}
}

break
}

case "random": {
let min = Number(args[4])
let max = Number(args[5])

if (isNaN(min)) {
error(`Minimum value should be number, got "${args[4]}": line ${lineNum}`)
return false
}
if (isNaN(max)) {
error(`Maximum value should be number, got "${args[5]}": line ${lineNum}`)
return false
}

if (min > max) {
const temp = min
min = max
max = temp
}

value = Math.floor(min + Math.random() * (max - min + 1))

break
}
}

vars[varName] = value.toString()

break
}


case "if":
case "while": {
const result = evaluateCondition(args, lineNum)
if (result == "err") {
return false
}

if (!result) { // Skip the next block
return "skipForward"
}

break
}

case "end": {
return "skipBackward"
}


case "delay": {
if (args.length <= 1) {
error(`Expected argument, got nothing: line ${lineNum}`)
return false
}

const num = Number(args[1])
if (isNaN(num)) {
error(`Expected number, got "${args[1]}": line ${lineNum}`)
return false
}

return "wait_" + args[1] * 1000
}


default: {
error(`Unrecognised statement "${args[0]}": line ${lineNum}`)
return false
}
}

return true
}


function evaluateCondition(args, lineNum, colNum) {
const conditionArg = args[2]
const leftArg = Number(args[1])
const rightArg = Number(args[3])

if (isNaN(leftArg) || isNaN(rightArg)) {
error(`NaN: line ${lineNum}`)
return "err"
}

switch (conditionArg) {
case ">": {
return leftArg > rightArg
}
case ">=": {
return leftArg >= rightArg
}

case "<": {
return leftArg < rightArg
}
case "<=": {
return leftArg <= rightArg
}

case "=": case "==": {
return leftArg == rightArg
}
case "!=": {
return leftArg != rightArg
}

default: {
error(`Unrecognised condition "${conditionArg}": line ${lineNum}`)
return "err"
}
}
}
</script>
</body>
</html>
ThisIsTemp1
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

I'm having trouble with this code, it isn't outputting anything after please wait

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
array as PlayerCards
while i < 7
random 1 50 as chooser
push PlayerCards {TypesofCards:chooser}
add {i} 1 as i
end
out {PlayerCards:2}
BigNate469
Scratcher
1000+ posts

Obscure - The brand-new, Turing-Complete, easy to use programming language

i_eat_coffee wrote:

i could use setTimeout() instead of while() for the ‘while’ block so it doesnt crash but then idk how to add a function to stop it if it runs infinitely
You might be interested in https://developer.mozilla.org/en-US/docs/Web/API/setInterval and https://developer.mozilla.org/en-US/docs/Web/API/clearInterval

Edit: If I counted correctly, this is my 3,000th post

Last edited by BigNate469 (Sept. 11, 2024 01:07:44)

Powered by DjangoBB