How do I Build a Interpreter

Just started using Construct 2? Post your questions here

Post » Tue Apr 22, 2014 8:53 pm

I have written a Interpreter in Javascript and other HTML5 platforms.

What the "Players" do is connect to a website and download a set of instructions.
I put these instructions into an array, then with a switch/case statement I call
functions that interpret the instructions, I got from the website, and preform actions
like draw a picture or play a sound. That way I can have one Player and many games.
Think of it as the very old Merlin game..(1978) or these 50 in 1 games from years ago
one interface or Player and many games.

Where do I start? I felt if I could get the Javascript-SDK to work, I would just find how
to do the net connection, and use the internal functions to preform the instructions.
As a newbie I am at a loss.

I want to use Construct2 because of the cross platform abilities.

Thanks
B
3
Posts: 4
Reputation: 183

Post » Tue Apr 22, 2014 10:25 pm

This isn't really a beginner topic and since you said you've made an interpreter before you likely know better than I on how to make one but here is a way to do it.
https://dl.dropboxusercontent.com/u/542 ... reter.capx

It's an interesting idea but it's probably better to just make the games in C2 and have one project that opens links to the other games.
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Wed Apr 23, 2014 2:01 pm

RoJohound thank you for the file.

I really need the other 3 parts.
Connecting to website.
Getting data into an array ( and with new Beta having better memory management) this will work better.
and looping through the array to pass the data to functions.

your example is good, but very very simple, compared to our instructions.
B
3
Posts: 4
Reputation: 183

Post » Wed Apr 23, 2014 4:29 pm

1. Look at the AJAX object for a way to download files from websites. I hear you can get more complicated communication if you make the website with PHP, but that's outside the scope of what I'm interested in.

2. You can either convert the text to an array with a for loop and using tokenat() and tokencount() kind of like in my capx, or you can directly add the commands to the array with the push action, one word at a time. After it's all in an array, you can use the array.asJSON expression to get a text representation of the array. In fact you can save a file with that to your website and use the array's download action and bypass the ajax object.

3. My capx was a simple example case of this. You'll have to add events to handle every function you want to use.

Overall the process to make an interpreter is much like doing it in any other programming language. It can get as advanced and complicated as you like.
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests