Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Lua to c++ Question

Discussion in 'General Discussion' started by moeman1989, Nov 9, 2018 at 4:46 AM.

  1. moeman1989

    moeman1989

    Joined:
    Sep 26, 2018
    Posts:
    10
    Hey guys.
    So I have been working with another engine and built a game with that. I want to bring the project over to unity.
    I haven't used C based languages before. I was wondering if there are any guides that would help me translate all my lua scripts to c++. Just to make things easier on me until I get the hang of c++.
     
  2. LurkingNinjaDev

    LurkingNinjaDev

    Joined:
    Jan 20, 2015
    Posts:
    1,172
    You wouldn't code in C++ if you choose Unity. You probably would code in C#, unless you buy source code license and build unity from source.

    Also it's very hard to translate Lua scripts to a full-blown C# or C++ code because of the systematic differences. You usually don't deal with that many staff in Lua. But it's not impossible, of course, just keep in mind that to translate your code is usually harder than rewrite it in a new language.
     
    moeman1989 likes this.
  3. moeman1989

    moeman1989

    Joined:
    Sep 26, 2018
    Posts:
    10
    Yeah ok thanks mate. I already suspected I might have to re-write everything. Was just kind of hoping translating was a little easier.
     
  4. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    2,091
    What I would recommend doing is building a small project from scratch in Unity just to learn the basics of the engine and work with C# a bit. Make a simple game where you can move a block around using keys on the keyboard.

    Then after that, I would suggest converting your lua scripts to pseudocode, and then convert that pseudocode to C#. C# is not difficult, but it will be different than lua. The language syntax is different and the engine API is different.
     
  5. moeman1989

    moeman1989

    Joined:
    Sep 26, 2018
    Posts:
    10
    Lua is very different from everything else I have seen. Its a lot simpler to use. But my previous engine didn't allow 64 bit games. Also unless I swap to a c based language I am going to struggle to add in steam controller support. Thanks for the advice though. I guess now I will need to sit and read through the unity API documentation.
     
  6. LurkingNinjaDev

    LurkingNinjaDev

    Joined:
    Jan 20, 2015
    Posts:
    1,172
    It's not really C-based language. It's C#, very different from C or C++.
    https://docs.microsoft.com/en-us/dotnet/csharp/

    For the Steam Controller part: https://assetstore.unity.com/packages/tools/utilities/rewired-21676 You can buy assets for almost anything you can think of, including multi-controller support.
     
    guavaman and moeman1989 like this.
  7. moeman1989

    moeman1989

    Joined:
    Sep 26, 2018
    Posts:
    10
    OMG thanks heaps mate. That Controller pack looks amazing.
     
  8. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    1,938
    What also you could do to try, use moonSharp for example. Is lua interpreted language on top of C#.
    So you can write for example core system in C#, then use lua, to run some of your lua code, before you translate them totally to c#. Or you may find, that some lua code may be still sufficient for your need as it is.
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,305
    As for Steam Controller support in Rewired, see this:
    http://guavaman.com/projects/rewired/docs/SupportedControllers.html#SteamController

    It does not wrap the Steam API. If you want to use the Steam API, C# bindings are available through various packages like Steamworks.net.

    As for C# in general, the syntax is pretty close to Java.
     
  10. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,813
    Even if conversion was straight forward, you'll need to spend a good amount of time not only learning C#, but learning the Unity API and how to use the editor. Creating games in Unity revolves just as much around setting up GameObjects in the editor as it does your C# code.

    I'd recommend spending some time with tutorials and learning to create something simple from scratch in Unity before embarking on porting your other game to Unity. Otherwise you're going to run into a lot of headaches if you don't understand how to do basic things in Unity. Start with some basic C# tutorials from another source, the Unity manual, the "Learn" section (see link at the top of every page), 3rd party tutorials for Unity on Youtube, etc. I called out C# tutorials separately since it is a standard programming language no Unity tutorials are going to teach C# to you, and will assume you already have at least the basics of the language down before working with Unity.
     
    Antypodish likes this.