can construct 2 allow code in the game

For developers using the Construct 2 Javascript SDK

Post » Tue Nov 29, 2016 6:04 pm

I want to build a game that allow players to code in the game, but i do not know is that possible
B
5
Posts: 2
Reputation: 229

Post » Tue Nov 29, 2016 6:30 pm

zrt720 wrote:I want to build a game that allow players to code in the game, but i do not know is that possible


You are probably going to need to provide more information about what you mean. What you have asked is very vague.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
86
Posts: 5,482
Reputation: 59,750

Post » Tue Nov 29, 2016 8:22 pm

zenox98 wrote:
zrt720 wrote:I want to build a game that allow players to code in the game, but i do not know is that possible


You are probably going to need to provide more information about what you mean. What you have asked is very vague.


I am trying to make a game that allow the players to write code in order to progress the game. i.e. This game is like "code in game". What I want is to let players code in a text box and compile what they coded then give some feedback to them. Simulating what compiler do but using game to present this. BTW the statement that below your answer was really nice. XD
B
5
Posts: 2
Reputation: 229

Post » Wed Nov 30, 2016 4:14 am

You could run the contents of the editbox as JavaScript using the browser object's execjs action. That is the simplest but the feedback would basically just be a return value. I suppose you could add some functions that call c2 functions to provide more feedback. But arbitrarily running js is an issue since absolutely any js can be run, which can be an issue.

You can look at the browser and function objects in the manual to see what I talk about above.

A more advanced thing you could do is make your own parser that reads the editbox a character at a time to do your own coding language. This gives much more control or what can and can't be done by the user. This can be as complex or as simple as you like. Probably not easy if it's not something you've done before.

I've done some expression parsers before that you can find on the forum, but reading outside sources may be more useful.

I guess it depends on what you actually want the code to do specifically and look like specifically.
B
94
S
33
G
113
Posts: 5,353
Reputation: 73,267

Post » Wed Nov 30, 2016 4:20 am

Here is a sample capx of loading external js file then executing these js code.
It is easy to modify this capx, to get js code from textbox.
B
109
S
27
G
276
Posts: 4,479
Reputation: 154,418


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest