This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-08-24 13:13:10

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

To Anyone Who Knows JavaScript: Question

So, in my progress with QuickCode, I decided to make a tiny language in JavaScript just to test my theory about how I will go about making QuickCode.

Basically, the only function in this mini language is "dialog."
Example:

Code:

dialog Hello

So this is the JS code I have so far for my parser:

Code:

dialogFunc = /^(dialog)\s(\w+)$/

function submitIt(myForm) {
if (dialogFunc.test(myForm.quickCode.value)) {
alert()
return false
}
alert("Invalid code!")
return false
}

Now, on the line

Code:

alert()

right under the if () statement, I want the alert to display the substring

Code:

(\w+)

of the regular expression as a string.

I need help on how to get the alert to do that!


Fork Clamor on GitHub!

Offline

 

#2 2011-08-24 14:11:57

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: To Anyone Who Knows JavaScript: Question

Nevermind, I finally got it after experimenting for a while

Code:

alert(RegExp.$2)

I was overthinking it  big_smile


Fork Clamor on GitHub!

Offline

 

#3 2011-08-24 19:14:57

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: To Anyone Who Knows JavaScript: Question

Nice username  tongue


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#4 2011-08-24 21:45:28

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: To Anyone Who Knows JavaScript: Question

rubiks_cube_guy238 wrote:

Nice username  tongue

Thanks.  big_smile


Fork Clamor on GitHub!

Offline

 

#5 2011-08-25 14:35:18

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: To Anyone Who Knows JavaScript: Question

This is very interesting. Does it work so far?

Offline

 

#6 2011-08-25 14:47:28

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: To Anyone Who Knows JavaScript: Question

Well, this tiny little programming language that I posted above works. My main project is QuickCode, and there's more about it in another thread on the Advanced Topics forum (I forgot the link). The QuickCode parser itself is about 1/2 done now, as I am continually hampered with bugs. So overall, it's coming along nicely, but I've still got a lot of work to do.  smile


Fork Clamor on GitHub!

Offline

 

#7 2011-08-25 14:50:02

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: To Anyone Who Knows JavaScript: Question

ohaiderstudios wrote:

Well, this tiny little programming language that I posted above works. My main project is QuickCode, and there's more about it in another thread on the Advanced Topics forum (I forgot the link). The QuickCode parser itself is about 1/2 done now, as I am continually hampered with bugs. So overall, it's coming along nicely, but I've still got a lot of work to do.  smile

Very cool.  big_smile

Offline

 

Board footer