Ask coding questions

← Back to all posts
`runBlocks()` function somehow not working
RixTheTyrunt

Can you please explain why is the runBlocks() function not converting blocks into JS? It is totally not working... AND EVEN NOT EXECUTING BUT INSTEAD LOGGING undefined!!!

Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
RixTheTyrunt
Comments
hotnewtop
SixBeeps

The very first block you make has an ID of "block1". When you go to compile the script though, the very first block you check for is "block0" which never exists. You put this as the condition for your while loop, so it just bails and does nothing to the code variable.

RixTheTyrunt

But... It makes the counter into 1 and the searches for block1

RixTheTyrunt

See line 50:

blockCount += 1;

RixTheTyrunt

It's before line 49, which is:

while (document.getElementById("block" + blockCount) != null) { // While a block REALLY EXISTS...

RixTheTyrunt

OHHH I'M SOO DUMB

MrVoo

You shouldn't be using eval()

RixTheTyrunt

THEN HOW SHOULD I EXECUTE THE CODE?!?!

SixBeeps

@RixTheTyrunt Making your own interpreter is a much safer option.

RixTheTyrunt

But how?

RixTheTyrunt

How is that possible?