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 haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  4. The Lich King has a new champion. The results for the 19th Icon Contest are here!
    Dismiss Notice
  5. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  6. 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.

[General] Back after 16 years, stuck on 2D Arrays globals.

Discussion in 'World Editor Help Zone' started by Macadamia, Feb 14, 2020.

  1. Macadamia

    Macadamia

    Joined:
    Jan 30, 2020
    Messages:
    197
    Resources:
    0
    Resources:
    0
    Hi everyone !

    First things first, my question, as people might not have time to read all my detailed explanations :

    How do you declare global 2D arrays in Jass without conflicting with the WE's Init Globals function ?

    I mean I have several arrays I use like this one :

    Code (Text):
    rect     array      WapPoint [4] [10]
    I did it to have a cleaner Jass code as I feel like using a single index is dirty coding.
    OF course this was not possible back in the days I was a mapmaker, but I read that that new vJass and JassHelper features allow multi-dimensional arrays.

    Fact is this is no lie, if I declare the globals like this in my script and don't use WE, the 2D arrays work a treat, so how can I make WE accept it ?

    I tried adding a custom Init Globals in the map custom script space (hoping it would run before all my custom triggers), and fun enough the whole map seems to compile with no error, until the last part when JassHelper just gives up with a pretty long list of unknown compile errors, starting, of course, at my "globals" first line.

    So, if vJass supports 2D arrays, and JassHelper compiles all the code referencing to these arrays like

    Code (Text):
    local rect WP=udg_WayPoint[PlayerNb][BallNb]
    then why can't we declare these arrays in globals with World Editor ????

    Any help would be immensely appreciated, as my project is 99% finished !




    Now for people with more time or patience, here is more about myself :

    I was a mapmaker back in 2003-2004, and although i stopped since, reforged pushed me back to my very old love!

    I was called ChrydGod back then on wc3campgains forum (seems it died recently, few days after I returned). I made several maps back then, including Atlantis Beyond Icecrown (DotA-like), Cube Defense NE and Cube Defense Balls Edition, they never really became popular, and that was deserved because I gave up mapmaking before being able to fix them.

    I'm back now, and slowly catching up with the knowledge I lost after these years, and trying to decipher all the amazing stuff that the community has brought over since I left. You guys just amaze me!

    Anyways, I have been working on a remake of my best map, Cube Defense BA, that will be called aMazing Balls TD. It should be really unique with features I haven't yet seen from all the other TDs around (although I was impressed by some of those made since I left!)

    I have lost count of the endless nights I spent working on it, especially with Reforged new bugs and features I had to find workarounds for, but it is nearly done. There is just a single issue :

    I work in World Editor as I did not find any other 3rd Party Editor working with Reforged, and to be honest this new JassHelper thing and vJass adoption (It didn't exist back then!). I am pleased with it anyways, and I manage to work on my Jass functions by throwing it in World Editor's empty triggers.

    So that is where the problem comes from : I could simply forget WE and remove its files from my map archive and just throw my war3map.j in with an MPQ Editor, but I really want to keep the thing usable in WE for the future, especially as I plan to release a non protected version for everyone once the project will be polished enough.
     
  2. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    875
    Resources:
    0
    Resources:
    0
    I'm not too sure about your issue but I would highly recommend taking a look into Lua if you aren't too deep in Jass already. It will make your life 100x easier.
     
  3. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Afaik the 2D arrays are not actually implemented as a native thing; they’re still just regular arrays where [x][y] = [x*MAX_Y + y]. It’s not clear to me what your problem is. We have free-declare globals now so anywhere you type a globals block you can declare variables; you do not have to try to inject into InitGlobals.

    There is a JNGP Lua edition that works with the recent patch but there’s not a whole lot of reason to use anything besides the (updated) vanilla WE now since it has full vJASS support.

    I’m not sure what you’re saying about protecting and war3map.j but that protection method should still work.

    Ditto what Uncle said about Lua. Skip JASS, learn Lua directly.
     
  4. Macadamia

    Macadamia

    Joined:
    Jan 30, 2020
    Messages:
    197
    Resources:
    0
    Resources:
    0
    Thanks for your input guys.
    Unfortunately, I am so "far into Jass" that I probably can consider I drowned myself in it :D
    I have no idea what lua is all about, but I definitely have plans to learn all I can about it

    Unfortunately, as my project is nearly completed, and as I spent so much time making the conversion between my old single -indexed arrays and my 2D ones, I had hopes I could release a playable version of my map, in order to enter the "live burning test" mode to start polishing features and balance for people who would enjoy it.

    I already had all my arrays with [x*maxX+y], and if I started trying to use 2D ones it's after reading some old post on these forums after using the search function. Someone was mentioning 2D arrays with vJass so I followed.

    Fun fact when I try to save my map, JassHelper does not complain about my 2D arrays, and if I add a syntax error to interrupt the compiling before landing to the strange unknown compilation error, I can see this in the processed code window :


    Code (Text):
        // User-defined    
    // processed:     unit array              udg_Ball [4][25]
    // processed:     unit array              udg_Flying [4][25]
    // processed:     destructable array      udg_PanelChar [4][24]
    // processed:     destructable array      udg_NamePanel [4][24]
    // processed:     destructable array      udg_WPNumber [4][10]
    // processed:     rect array              udg_WP [4][10]
    // processed:     real array              udg_WPx [4][10]
    // processed:     real array              udg_WPy [4][10]
    // processed:     trigger array           udg_KilledBall [4][25]
    // processed:     trigger array           udg_ResizeBall [4][25]
    // processed:     trigger array           udg_NextWayPoint [4][25]
    // processed:     trigger array           udg_BlockedBallAttacks [4][25]
    // processed:     integer array           udg_Destination [4][25]


    //JASSHelper struct globals:
    unit array s__udg_Ball
    unit array s__udg_Flying
    destructable array s__udg_PanelChar
    destructable array s__udg_NamePanel
    destructable array s__udg_WPNumber
    rect array s__udg_WP
    real array s__udg_WPx
    real array s__udg_WPy
    trigger array s__udg_KilledBall
    trigger array s__udg_ResizeBall
    trigger array s__udg_NextWayPoint
    trigger array s__udg_BlockedBallAttacks
    integer array s__udg_Destination
    Once I remove the syntax error I added, it processes the whole code and then starts some kind of different type of checking before validating, and that's where I get hundreds of unknown errors labeled as "syntax error" starting with my custom globals declaration line.

    I understand how much I have missed since 2004, and also how much work I have to invest in order to understand all the tools that are available now.

    Oh about protection : I just know it is a good thing to protect a map from common stupid editing, so I will first release a protected version, until the map is good enough to be enjoyable, then If I host it here on the Hive, I believe protection will make no sense as people will always know how to grab the un-tampered version. I currently am using this Vexorian Map Optimizer I found on these forums - again something I didn't have back in 2004 - and with enough caution, it does a great and clean job.

    So protection here is not an issue - especially as it is temporary - but definitely trying to make 2D arrays declarations to work.

    Back in 2004, the community was very active but we had very few tools, people used to considered as an expert by then - i fell the exact opposite today. I wasn't that good, I was just stubborn and never gave up on "this is not possible". That's how I made my scrolling text panels on the floor.

    If it really can't be done, I am willing to convert my whole code again, but that would feel like giving up.
     
  5. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,926
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Make sure World Editor has JASSHelper turned on. It is needed to compile the vJASS 2D arrays.

    Be aware that they are emulated 2D arrays. This is why they require size fields so that the system than reserve enough space for each dimensions.

    The maths to dereference a specific index of the array looks somewhat like...
    Y * X_length + X.

    The X_length with Y_length product is used to determine how many arrays must be allocated and joined together in a tree to back such a 2D array. This logic may be old and so not factor in the much larger arrays added by a recent patch.
     
  6. Macadamia

    Macadamia

    Joined:
    Jan 30, 2020
    Messages:
    197
    Resources:
    0
    Resources:
    0
    Thanks, yes i had JassHelper enabled, with every option but the debugging one.

    Nothing worked, fun enough even without using 2D arrays, I did not even manage to set a custom globals/endglobals section without JassHelper crying out for Syntax Errors, the same kind you get when you forget an endif somewhere.

    Anyways, as I had to move on with my project, I used Notepad++ to help changing all the dual indexes back to the usual [i+iMax+j]

    Will investigate later, when I start learning subtleties of vJass and other new coding ways for wc3.

    My project is virtually ready for release in these forums, just currently tracking a couple of remaining bugs.

    I hope people will enjoy it, this map is also some kind of demo of a multitude of things you can do for a custom map with just Jass and some very basic model editing.

    Thanks again !
     
  7. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    I don't know if putting a space between the variable name and its sizes will work properly. Probably, but I'm not entirely sure. I've always written as Var[x][y] not Var [x][y]. I think the actual issue is that you are trying to overwrite arrays you have already created with the GUI variable editor? I say that because all of your defined arrays have the udg_ prefix (udg_Ball [4][25] for example), which is normally indicative of a variable-editor-created variable. While in GUI it is possible to locally shadow globals by reusing their name in a trigger, you cannot overwrite something in the way you are doing here (if that's what you're trying). If that's not the case, know that your variables do not have to start with udg_ at all.

    Overall I'm still not sure what problems exactly you're having since I can't see the errors it's throwing. Perhaps it would be simplest to upload your map here (or send in a PM to me if you're not comfortable uploading it) so I can look. Just disable any/all triggers that are throwing errors and eventually it will be able to be saved.
    AFAIK optimizer doesn't work now...? Or at least not like it should.
     
  8. Macadamia

    Macadamia

    Joined:
    Jan 30, 2020
    Messages:
    197
    Resources:
    0
    Resources:
    0
    Hi !
    When I attempted to use 2D array declarations, what I did was :
    1) grab the globals sections of my map within war3map.j
    2) delete all globals from the Trigger Editor
    3) Create a new custom script in the Variables section
    4) Paste my entire globals sections
    5) removed all initial values as i planned to initialize all globals at map init
    6) changed the arrays i wanted to become 2D by adding these [x] [y] , with the space you are mentioning (maybe THAT was the issue ?)
    That is why you see all these udg_ prefixes. I was tempted to remove them, until I realized I needed to differentiate globals from locals. At some point I even thought the udg_ prefix was the problem, so I tried replacing all globals prefixes with g_, and that made no difference.

    I am currently starting to educate myself with the new notions like vJass and such - when not working on the map - and maybe I did something wrong that is hardly noticeable, a common thing with coding. I might try these 2D arrays again.

    The reason is code readability. That is the same reason I am considering vJass : to use libraries to be able to properly declare my global functions where I want them to be.
    This seems important to me, as nearly everything in the map stands within the Jass code, and the only things created outside the Trigger Editor are the properties of custom units / abilities / buffs / effects / destructables / doodads, and of course Terrain and Assets.

    I also wish the map script to be easy to read once I release the unprotected version, and I intend to add comments in most "triggers". Adding all my global functions to the top custom script section would really make it painful for any Jass beginner.

    As for Vexorian's Map Optimizer, it worked a treat last time I tried it on my map. This said, it might simply be because until now I have only used standard Jass ?

    I am not yet comfortable with uploading the map publicly yet, but I will soon send you a version that is not messed up. I have this decease , you know the one that makes you add features as soon as you have fixed the last one :D, so I will stop where I am, and as soon as the latest 3 towers will be finished and the last bug fixed, I will send you the map via PM so you can at least give me your opinion on adding 2D arrays or libraries for readability.

    Thank you !
     
    Last edited: Feb 17, 2020
  9. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,926
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    2D arrays should only work in custom script globals blocks as that is what JASS Helper will expand from. I do not think JASS Helper expects the actual globals block to be modified.
     
  10. Macadamia

    Macadamia

    Joined:
    Jan 30, 2020
    Messages:
    197
    Resources:
    0
    Resources:
    0
    Sorry, I will sound dumb on that one but I seem to misunderstand what you are saying. Isn't pasting the globals block into a custom script section in the Trigger Editor any different from a "custom script globals block" ?

    I understand Jass can only accept 1 globals declaration, I was assuming JassHelper would "inject" my own globals block into the final script's.

    Thanks for your patience guys, I still have a lot to figure out, and right now I have just about caught up with my knowledge back from 2004.

    The bad thing is I am probably late on all the amazing progress the community has made since I left.
    The good thing is I still have a lot of ideas : some are unrealistic, some are new, some have just been tried so many times that it makes them boring.

    But trust me, I still think I can surprise the community ! Would just be a fair return to all the amazing things talented people have made when I was in hibernation :D

    By the way, fixed the last bugs I found, all I have to do now is :
    - Replace all spells creating terrain deformations (as I have read it was generating a lot of lag)
    - Complete the last tower and its 2 upgrades (simple slow auras + a basic scripted "FlashForward" spell moving the target to the next waypoint but with reduced HP)

    Once these 2 things are done, I can send you both the final map prototype so that you can have a look at it.
     
    Last edited: Feb 17, 2020
  11. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    It does inject.
    DSG misunderstood and thought you were injecting your variables directly into the map script globals block. That is what he thinks JASSHelper will not look for. What you did is correct: create a new globals block literally anywhere else.
    You want to avoid them because deformations can very easily cause desyncs. The deformation doesn’t exist for players that don’t have direct vision of the area it affects, so things like GetLocationZ will return asynchronous values when used in that area while the deformation is happening.

    As far as unknown compile errors: when this has happened to me it’s because of a hidden/invisible character that’s in one of my lines. Deleting the whole line and retyping it (without copy/paste) has fixed it for me.
     
  12. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,926
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    It does if you create a custom globals block and not modify the one in the war3map.j. There might have been a misunderstanding with how your steps were worded.
     
  13. Macadamia

    Macadamia

    Joined:
    Jan 30, 2020
    Messages:
    197
    Resources:
    0
    Resources:
    0
    Thanks for all your input, this is really helpful !
    So I assume I have some kind of rogue character somewhere that prevents the compilation to terminate.

    I think it is still there dormant somewhere, even if I reverted back to 1D arrays, as every time I load my map in World Editor, there is a variable with no type and no name that I can't even change (just delete). Haven't found the rogue character yet, but I'll track it pretty soon.

    I have just about finished the map, It should be quite a surprise as it is not really looking like normal maps. I have read a talented person has made a very advanced map called YouTD(I seem to have read a document about it looking like a university project). I have found the page about its release here on the forums. Unfortunately I could not access the website, I hope it is only a temporary issue.
    Anyways, having read YouTD post made me realize that he did something I had always dreamed of 16 years ago. The map seems amazing in all aspects !!!

    This said, although being less advanced, I believe aMazing Balls TD remains something unseen before, at least on several aspects.

    The map now works. I can't seem to find any but so far, and the only thing left to do is replace Terrain Deformations spells - shouldn't be too hard as there are only 3 variants (rather 3 separate levels) of a single kind of thunderclap and a hero variant of slam with 6 levels.

    I am not a great fan of this idea of using dummy units to make custom spells so I haven't used any yet. But after a lot of reading, I realize this is often the only way to go. I will then use dummy units with locust to cast a stun in area. I haven't found any other AOE stun from the pool of existing spells that do not deform terrain. So time to use Jass for the matter.


    Once these completed and bug-free, I will test my map solo on Bnet, then release a protected playable version on The Hive.
    I will only send it unprotected to people who are really interested, and I will be grateful for any feedback on balance issues and things that could or should be improved.
    I don't expect Jaws to drop, as I would have in 2004 with this version, but I hope people will find it entertaining and help me make this map an enjoyable one to play.

    Oh as a side note, maybe I am responsible for not getting perfectly understood. English is not my mother tongue so I sometimes don't express myself the right way, although I keep trying to improve my grammar !

    Thanks again for your help guys, much appreciated.