Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FamilyFriendlyUsername · May 17, 2018 at 09:28 AM · guieditortext

Is it possible to make a code simulator?

Hey, so I was wondering how difficult it would be to implement a code editor that runs a real life language in the game. This is for a game mechanic that I’ve been refining and wondering how hard it would be to do this.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by JackMini36 · May 17, 2018 at 10:04 AM

I made something similar a few years ago, but with a simplified language not a real one.

It is complicated to parse the code effectively and translate that into game logic yourself. You can go on and study a bit about code parsers and how they work and implement a sophisticated one youself.

What we did was just some text processing and finding certain patterns which made up the simplified language we came up with. Specific patterns or keywords where matched with specific game logic, so whenever a match was found we executed that logic based on the variables defined that followed those keywords/patterns.

If you don't necessarily need to use a real language, you can make up your own simplified version to fit your game mechanics. For example, our for loop was something like this:

 // Iterate a specific number of times
 for(10)
 {
     function();
 }

  // Iterate a specific number of times (stored in a variable)
 for(iterations)
 {
     function();
 }

This can be achieved by simple parsing and text processing. However it gets way more complicated with nested fors, ifs and so on. I remember it being a pain in the ass to make.

EDIT: This is the demo we made. I don't still have working demo since it is not mantained http://www.jackhadjicosti.com/project/3/Coducation

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by troopy28 · May 17, 2018 at 06:09 PM

Yes! It is!

What you would have to do is called "hosting". And it is exactly what Unity is doing with your C# scripts: they are hosted by their C++ codebase through Mono, and are called (and managed) from this C++ code. Now, as you are already using C#, you wouldn't have to suffer the process of embedding a language from C++, which is not always that funny.
I would recommend you to host a C# script engine, as you are using C# Unity scripts, because there are a lot of ways to do this, and it would allow you to have a great interactivity between your C# host (Unity scripts) and the C# hosted scripts. I suggest you to have a look at CS-Script, which seems to be great, and more importantly, read about Microsoft's Roslyn managed compiler, which allows you to do a lot of things about C# hosting (and other .NET languages if I'm not wrong).

Now if you want a more "scripty" language, like Python or Lua, well, there are libraries dedicated to this, like IronPython for Python hosting, or MoonSharp for Lua (which seems to be truly compatible with Unity, see here).

But I recommend you to go for C#. It would be really something easy to do.

Good luck on the path!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

175 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Detect Text in GUI; Print 1 Answer

Unity editor GUI, how to prevent "passthrough"/"clickthrough" etc? 0 Answers

GUI text font change 3 Answers

Limit on GUI Components? 0 Answers

Display the set up key for a button 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges