1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

JNGP Lua Edition - Combining JASS/vJass/Lua

Discussion in 'Warcraft Editing Tools' started by TriggerHappy, Apr 27, 2019.

  1. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,665
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    JNGP Lua Edition

    Archive Password: "thw" (without quotes)

    Google thinks JNGP is malware so it has to be password protected. You can read more about it on the official JNGP page.

    As it currently stands in the latest World Editor, you cannot mix scripting languages. You must pick either JASS or Lua. You also cannot require scripts in WC3's Lua so we are essentially forced to type all of our code in an external editor and paste it back into the trigger editor. Because of these limitations I decided I wanted to try and integrate Lua into the editor while also allowing you to code in JASS or vJass.

    How to Setup
    • Make sure you have a copy of an older version of WC3. You can download the 1.26 game files here. It should work with any patch that contains the MPQs.
    • Download extract jassnewgenpack-lua-1.1.0.zip.
    • Edit "findpath.lua" (in the jngp folder) to point to your WC3 directory and 1.31 executable. There are comments in the file which explain further.
    • Run "NewGen WE.exe".

    Using Lua

    In order to use Lua you must wrap your code in
    //! lua
    and
    //! endlua
    tags. For example:

    Code (Lua):
    //! lua
    function Trig_Basic_Example_Actions()
        TimerStart(CreateTimer(), 1.00, true, function()
            print("Lua!")
        end)
    end
    //! endlua

    Now, if you want call a Lua function from within JASS you must use the
    //# +nosemanticerror
    tag to prevent PJASS from throwing errors. For example:

    Code (vJASS):
    //! lua
    function Trig_Basic_Example_Actions()
        TimerStart(CreateTimer(), 1.00, true, function()
            print("Lua!")
        end)
    end
    //! endlua

    //# +nosemanticerror
    function InitTrig_Basic_Example takes nothing returns nothing
        set gg_trg_Basic_Example = CreateTrigger(  )
        call TriggerRegisterTimerEventSingle( gg_trg_Basic_Example, 0.00 )
        call TriggerAddAction( gg_trg_Basic_Example, function Trig_Basic_Example_Actions )
    endfunction

    The same rules apply when you are using vJass.

    External Lua Files

    Because JassHelper's import directive wasn't working properly I made a quick one specifically for Lua files.

    Code (vJASS):
    //! luaimport "luascripts\test.lua"

    You can use relative or absolute paths. This should allow you to easily code in a 3rd party code editor if that's what you want.

    Lua VSCode Integration
     

    Attached Files:

    Last edited: May 31, 2019
  2. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    351
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    Thank you for this!
     
  3. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,665
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    Updated to 1.1.0
    • Implemented recursive includes. You can import a script from the editor, and those scripts can include other scripts.
    • Combined all the luahelper scripts into a single executable (saves +10MB).

    includes.png
     
  4. Darklycan51

    Darklycan51

    Joined:
    Jan 12, 2011
    Messages:
    1,325
    Resources:
    3
    Maps:
    3
    Resources:
    3
    +1 this extension is really useful
     
  5. yxq1122

    yxq1122

    Joined:
    Jun 5, 2018
    Messages:
    107
    Resources:
    0
    Resources:
    0
    Thanks for your nice work!
     
  6. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,611
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    Seems promising for those that somehow like lua ;)
     
  7. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,036
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Do you know if this gets around the issue of maps requiring all triggers be removed or a new map being created in order to allow Lua scripting?

    I think Lua is great, but the integration with exisiting script is difficult for laymen and I fear will reduce its adoption among the novice parts of the community who have shied away even from JASS.
     
  8. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,665
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    Yes you can open any old map and start using Lua. You don't need to disable anything.

    However you cannot open a map that was created with the 1.31 PTR in this JNGP, at least until/if I finish the convert map feature.
     
  9. Drynwhyl

    Drynwhyl

    Joined:
    Nov 21, 2016
    Messages:
    18
    Resources:
    0
    Resources:
    0
    I tried to use this jngp and encountered an error while trying to run test map, but after pressing 'ok' map still starts. But for some odd reasons it leaks local variables when running in such way. Starting the same map from the game client does not produce leaks though.

    UPDATED:
    I've tested map once again and realised that only temporary test map get properly converted to Lua, but the real one does not. So the question is how to make map convert to Lua on save? And is it ok for Lua to leak handles even after nulling? I'm not quite sure how Lua works internally but I think would not be possible to implement things like closures with access to local variables from the enclosing function if local variables behaved as before, in JASS.
     

    Attached Files:

    Last edited: May 20, 2019
  10. sonphamthe11H

    sonphamthe11H

    Joined:
    Mar 6, 2017
    Messages:
    118
    Resources:
    0
    Resources:
    0
    upload_2019-5-21_20-10-38.png how to fix this?
    edit: this happens even I restart my computer
     
  11. Drynwhyl

    Drynwhyl

    Joined:
    Nov 21, 2016
    Messages:
    18
    Resources:
    0
    Resources:
    0
    Make sure "path" variable in file "findpath.lua" is set to folder with game MPQs.
     
  12. sonphamthe11H

    sonphamthe11H

    Joined:
    Mar 6, 2017
    Messages:
    118
    Resources:
    0
    Resources:
    0
    it's in right directory
     
  13. sonphamthe11H

    sonphamthe11H

    Joined:
    Mar 6, 2017
    Messages:
    118
    Resources:
    0
    Resources:
    0
    fixed,miss a "/"
     
  14. FeelsGoodMan

    FeelsGoodMan

    Joined:
    Dec 13, 2018
    Messages:
    463
    Resources:
    1
    Maps:
    1
    Resources:
    1
    If you made this possible it would be really, really, really awesome!
     
  15. Nudl9

    Nudl9

    Joined:
    Nov 9, 2006
    Messages:
    2,149
    Resources:
    26
    Icons:
    11
    Skins:
    1
    Maps:
    14
    Resources:
    26
    The editor crashes when i try to load certain maps:
    -Warcraft Royale crashed (saved with 1.30)
    -Terrace Field (Melee map saved with 1.30)

    I had Gnoll Wood lying around and that seemed to work.
     
  16. pOke

    pOke

    Joined:
    Mar 24, 2013
    Messages:
    1,101
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Pretty sure I had this working the other week, however, while I am able to open/save/compile I cannot run test. When I try to test, it hangs for a second then appears like it spams a few command prompts then closes them. It goes onto open the newer blue dialog box to Repair or Launch TFT. I then press launch and it is the main menu of Wc3 1.31.

    Made a test map just to check bare bones, obviously can open/save/compile, still opens the main menu as stated above. However, if I place testmap in maps wc3 folder for the 1.26 version and go in single player I am able to test it. That will be a rather big inconvenience.

    Any insight would be appreciated!
     
    Last edited: Jun 13, 2019
  17. pOke

    pOke

    Joined:
    Mar 24, 2013
    Messages:
    1,101
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Any advice?

    When I try to test w/ lua code, I get an error "Failed to execute script luahelper"

    Edit: Got word from TriggerHappy on discord, he says it needs to be updated, and that he is in the process of moving over to Ceres.
     
    Last edited: Jun 13, 2019