• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] comments cause crashing???

Status
Not open for further replies.
Level 6
Joined
May 7, 2009
Messages
228
Well I had yet more trouble with my map today. Warcraft crashes when you try to create a game with it, for no discernible reason.

After a great deal of trial and error, I managed to trace it down to a single commented out line. Which is why I am baffled. Comments aren't supposed to affect the game at all. Why would their inclusion cause crashing? Why does Warcraft hate me?

For example the follow code works perfectly fine,
JASS:
globals
    constant real startdist = 500
    integer numplayers=0    
    integer array slot
    integer array kills
    integer array deaths
    integer array s2p
    unit array ship
    real array shipx
    real array shipy    
endglobals

function main takes nothing returns nothing
endfunction

function config takes nothing returns nothing
    local integer i=0 
    call SetMapName("")
    call SetMapDescription("")
    call SetPlayers(12)
    call SetTeams(12)
    call SetGamePlacement(MAP_PLACEMENT_TEAMS_TOGETHER)
    loop
        exitwhen i>=12
        call DefineStartLocation(i,0,0)
        call SetPlayerStartLocation(Player(i),i)
        call SetPlayerColor(Player(i),ConvertPlayerColor(i))
        call SetPlayerRacePreference(Player(i),RACE_PREF_HUMAN)
        call SetPlayerRaceSelectable(Player(i),true)
        call SetPlayerController(Player(i),MAP_CONTROL_USER)
        call SetPlayerTeam(Player(i),i/6)
        set i=i+1
    endloop    
endfunction

Yet this code will cause an instant crash. What gives?
JASS:
globals
    constant real startdist = 500
    // Warcraft 3 sucks! 
    integer numplayers=0    
    integer array slot
    integer array kills
    integer array deaths
    integer array s2p
    unit array ship
    real array shipx
    real array shipy    
endglobals

function main takes nothing returns nothing
endfunction

function config takes nothing returns nothing
    local integer i=0 
    call SetMapName("")
    call SetMapDescription("")
    call SetPlayers(12)
    call SetTeams(12)
    call SetGamePlacement(MAP_PLACEMENT_TEAMS_TOGETHER)
    loop
        exitwhen i>=12
        call DefineStartLocation(i,0,0)
        call SetPlayerStartLocation(Player(i),i)
        call SetPlayerColor(Player(i),ConvertPlayerColor(i))
        call SetPlayerRacePreference(Player(i),RACE_PREF_HUMAN)
        call SetPlayerRaceSelectable(Player(i),true)
        call SetPlayerController(Player(i),MAP_CONTROL_USER)
        call SetPlayerTeam(Player(i),i/6)
        set i=i+1
    endloop    
endfunction
 
Level 4
Joined
Nov 23, 2007
Messages
113
Perhaps try initializing the constant real variable with a real value as it may cause some strange anomaly when initialized with an integer followed by a comment line (a quirk in the byte code, perhaps). I can't remember if I've ever tried in jass to initialize a constant real with an integer followed by a comment line, so I can't say but it may be worth a shot for curiosity sake, if anything.

constant real startdist = 500.0

Also, I didn't know function main() could be empty. I thought there had to be at least a call to InitBlizzard().

In any event, maybe have a look at the outputwar3map.j file in jasshelper's log folder to see what is actually being produced by the compiler under the two different circumstances.

Sorry I couldn't test the above before commenting, as I have to get to work.
 
Level 6
Joined
May 7, 2009
Messages
228
Perhaps try initializing the constant real variable with a real value as it may cause some strange anomaly when initialized with an integer followed by a comment line (a quirk in the byte code, perhaps). I can't remember if I've ever tried in jass to initialize a constant real with an integer followed by a comment line, so I can't say but it may be worth a shot for curiosity sake, if anything.

constant real startdist = 500.0

Also, I didn't know function main() could be empty. I thought there had to be at least a call to InitBlizzard().

In any event, maybe have a look at the outputwar3map.j file in jasshelper's log folder to see what is actually being produced by the compiler under the two different circumstances.

Sorry I couldn't test the above before commenting, as I have to get to work.

Where do you get Jasshelper? I looked in THW Tools section but I didn't see it.

The first one shouldn't work. You've got two main and two config functions (or you're not showing us all your code).

What are you talking about? There's only one of each.
 
Level 4
Joined
Nov 23, 2007
Messages
113
Where do you get Jasshelper? I looked in THW Tools section but I didn't see it.

http://www.wc3c.net/showthread.php?t=88142

I use jasshelper as a standalone compiler simply because I find it quicker for what I am doing and I prefer my own text editor with scripting (UltraEdit). This way I rarely have to use the WE other than when I design the initial map, so I can work on the triggers independently. Additionally, this method allows me to update the triggers in all 30+ maps in one go using a batch file.

However, if you're writing triggers specific to each map and tend to edit the map itself as you are writing the triggers (as opposed to writing the triggers after the map design is completed), you are probably better off doing it the way Eleandor suggests.
 
Level 4
Joined
Nov 23, 2007
Messages
113
I don't see how it can compile with an empty main() function because the vjass compiler itself appears to require a call to InitBlizzard().

The only way around this that I know of is to use the following method inserted in the main function (which is also not present):
//! inject main

//! dovjassinit
// call InitBlizzard( )
//! endinject
 
Level 15
Joined
Jul 19, 2007
Messages
618
warcraft does not suck its u who is hacking the config and main that crashes the game! u know main must not be empty... each config and main are not executed at same time and they must follow there execution order! and each action must be sorted! dont inject if you dont know how warcraft iii works!

comments in globals work fine!

EDIT:
Mannoroth said:
I don't see how it can compile with an empty main() function because the vjass compiler itself appears to require a call to InitBlizzard().

The only way around this that I know of is to use the following method inserted in the main function (which is also not present):
//! inject main

//! dovjassinit
// call InitBlizzard( )
//! endinject

no InitBlizzard() is the reason why i injected the stuff! to remove it coz it causes handle leaks and loads all custom stuff! but most of bj-s will not work and game itself if u dont know what u need to recode (if u need this parts) for example custom item shops which generate random items!

however InitBlizzard is a must to be removed coz else there is no point in injecting!
 
Level 4
Joined
Nov 23, 2007
Messages
113
warcraft does not suck its u who is hacking the config and main that crashes the game! u know main must not be empty... each config and main are not executed at same time and they must follow there execution order! and each action must be sorted! dont inject if you dont know how warcraft iii works!

comments in globals work fine!
I have no idea who that comment was directed toward. :/


no InitBlizzard() is the reason why i injected the stuff!
the reason why you injected "what" stuff? What are you talking about?

to remove it coz it causes handle leaks and loads all custom stuff! but most of bj-s will not work and game itself if u dont know what u need to recode (if u need this parts) for example custom item shops which generate random items! however InitBlizzard is a must to be removed coz else there is no point in injecting!
I don't see how any of this is related to my comment. He has an empty main() function. vjass requires a call to InitBlizzard() (which Vexorian intends on removing in the future). The only way to successfully compile an empty main function that I know of (which is mostly useful in an ai file) is with the method I described. That's all I was stating. Whether this was the OP's intent or not is unknown.
 
Level 14
Joined
Nov 18, 2007
Messages
816
alright... either you injected the main function, in which case that code shouldnt pass through JassHelper, or you redeclared the main and config function, in which case PJASS should complain. I hope you didnt try to modify those two functions by editing them after compiling the map, since that can and will cause errors (if youre not an expert).
 
Level 6
Joined
May 7, 2009
Messages
228
I hope you didnt try to modify those two functions by editing them after compiling the map, since that can and will cause errors (if youre not an expert).

Well I guess it's a bit late, but yeah, that's exactly what I was doing. At the time, I didn't have JNGP or vJass or whatever, and was editing the .j file directly to write my triggers. What I posted was the entire war3map.j file for my map.
I never did figure out why the comment was causing weird behavior.

Anyway, I started using vJass, so hopefully I won't get the problems associated with editing it directly now.
 
http://www.wc3c.net/showthread.php?t=88142

I use jasshelper as a standalone compiler simply because I find it quicker for what I am doing and I prefer my own text editor with scripting (UltraEdit). This way I rarely have to use the WE other than when I design the initial map, so I can work on the triggers independently. Additionally, this method allows me to update the triggers in all 30+ maps in one go using a batch file.

However, if you're writing triggers specific to each map and tend to edit the map itself as you are writing the triggers (as opposed to writing the triggers after the map design is completed), you are probably better off doing it the way Eleandor suggests.


how do you change the triggers of numerous spells all at once?
 
Level 4
Joined
Nov 23, 2007
Messages
113
I think the term "change the spells" is what confused me (as opposed to "add spells to a map or many maps").

Adiktuz, if what you want to do is add some spells to all your maps (or a bunch of them), let me know and I will explain how to set it up. I don't want to write a lengthy off-topic post for others to wade through if this isn't even what you were asking for.
 
Level 4
Joined
Nov 23, 2007
Messages
113
Sorry, I don't know where the "paste bin" is so I'll just post it here and perhaps the mods can move it to a more appropriate place.

---------------------------------
Using the command line version of jasshelper

The first thing you need to do is create .j source files from your triggers. So for example, if you have a spell trigger SpellA and a number of common functions in your custom script code section, copy and paste them into a blank editor window (such as notepad - I prefer UltraEdit), then save them as individual .j files.

For example:

CommonFunctions.j
SpellA.j
SpellB.j
MultiBoard.j
AIBugFixes.j

NOTE: You can, of course, copy all the code to one file but if you're like me and have thousands of lines of code, this can be very messy.

Typically, I keep all my source files in "Warcraft III\Scripts\Trigger Scripts"

What I do is... instead of using //!import in my source files, I use a single source file that does nothing but import all my files in correct order, and contains one function at the bottom of the file to call all the InitTrig functions. This will make setting up your exported map script file much quicker and easier and produces one output file with all your code.

Example:

JASS:
//! import "CommonFunctions.j"
//! import "SpellA.j"
//! import "SpellB.j"
//! import "MultiBoard.j"
//! import "AIBugFixes.j"


function InitExternalTriggers takes nothing returns nothing
   call InitTrig_SpellA( )
   call InitTrig_SpellB( )
   call InitTrig_MultiBoard( )
   call InitTrig_AIBugFixes( )

endfunction

The file above in my case is usually called "TriggerImports.j"

NOTE: Remember to set default directories in jasshelper.conf to simplify. For example, I have the following in my jasshelper.conf so that I don't have to include the directory in each import reference:

[lookupfolders]
".\jass\"
"C:\Gaming\Warcraft III\Scripts\Trigger Scripts\"
"C:\Gaming\Warcraft III\Scripts\Trigger Scripts\Map Exports"
"C:\Gaming\Warcraft III\Scripts\AI Scripts\"

Exporting Your Map Files
I assume most people design their map first, then write the triggers for it. If you are going to work with the command line version and use a text editor to write triggers from scratch as I do, then doing it in this order will make things much easier. This is because any time you change your map, you need to export the map script and recompile.

The reason for this is in the way that jasshelper adds the code directly to the map. After jasshelper inserts your trigger code into the map, you can open the map and trigger editor in WE, but you will see that there are no triggers there to edit (even though they are still in the map). Some people may like this because people can't edit or copy your triggers in the trigger editor.

However, if you save the map in WE, the triggers that jasshelper inserted will be stripped and thus you must export the map script and compile it again. This is why it's best to get all your map design done first, then write your scripts for it.

Once you've finished your map, export the map script (I use the following folder: "Warcraft III\Scripts\Trigger Scripts\Map Exports"). Typically you'd use the same name as the map, but with a .j extension. However, I add an extra step so that I can maintain both the original exported script and the edited version (so you don't lose the original).

Example:
MyMap-export.j

Setting up your exported map script for compiling

I'm lazy, so I use a javascript I wrote for UltraEdit to do this for me, but the process is pretty simple.

1. Open up your exported map script in a text editor (not a word processor)
2. Scroll down to the main() function at the bottom of the file.
3. At the bottom of the main() function (just above the endfunction statement), insert the following code

call ExecuteFunc("InitExternalTriggers")

InitExternalTriggers is the function you created in the import file "TriggerImports.j" above.

4. Add an import statement to the bottom of your map script file (at the very bottom below all the script code). So in our example, it would be:

//! import "TriggerImports.j"

This is the file you created above to import all your source code in one statement.

That's it. All you have to do is add these 2 lines of code to your exported map script.

5. Save the edited map script file with a different name such as "MyMap.j" (I just omit the "-export" part) in the same folder.

Now your map script is ready to be compiled.

Compiling your map script and adding it to your map
I know it sounds like a long process if you have a lot of maps but really the only lengthy part is exporting all your map scripts from all your maps that you want your trigger code inserted into. As long as you aren't constantly editing the map design itself (not the trigger code), you should only have to do this once when your map design is completed. After that, you can edit your triggers and test your map without ever having to open WE.

First you will want to create a shortcut to a DOS PROMPT so that it opens in the jasshelper folder each time (less typing).

1. Goto your Start->Accessories and right click on Command Prompt and select Copy.
2. Open My Computer and navigate to your jasshelper folder and press Control-V to copy the shortcut. You can put this shortcut anywhere you want where it's easy to access. The important thing is setting the "Start In:" location below.
3. Right click on the command prompt shortcut and select Properties
4. On the Shortcut tab in the "Start In:" box, type the name of the folder where jasshelper is (the folder where you just copied the command prompt shortcut). Make sure the folder path is enclosed in quotes.
5. Click [OK]

Creating your batch file to compile a single map
For this, we'll be using the command line version of jasshelper, clijasshelper.exe. The syntax is as follows:

clijasshelper.exe [OPTIONS] common.j blizzard.j exportedMapScript.j MapFile.w3x

To create your batch file, create a new text file in notepad (or your favorite text editor - cannot be a word processor). Then create the call to jasshelper using the example below but with the folder locations you are using and naming method:

clijasshelper.exe common.j blizzard.j "C:\Gaming\Warcraft III\Scripts\Trigger Scripts\Map Exports\%1.j" "C:\Gaming\Warcraft III\Maps\MyMaps\%1.w3x"

Then save the batch file to your jasshelper folder. I save mine as "vJassMap.bat".

NOTE: Since this actually edits your map file directly, I suggest you make frequent backups of your maps in case something screws up (as is the case when using the WE method as well). You could automate this in the above batch file so that every time a map is compiled, it is first backed up. For example, above the first line in the above batch file (prior to the compile command) you could insert the following command:

copy "C:\Gaming\Warcraft III\Maps\MyMaps\%1.w3x" "C:\Gaming\Warcraft III\Maps\Backup\%1.w3x"

Leave a space between the above command and the compiler command.

Compiling Your Map
Now that you have everything set up, compiling your map from now on is quick and easy. Just open your command prompt (which I keep open while I'm editing) and type in the following command and press [ENTER]

vJassMap MyMap

Where "MyMap" is the name of the map you want to compile.

This makes editing and testing your map rather easy as you can make changes to any of your source files, then simply use the above batch command to compile it. Since you aren't saving the entire map (and don't even have WE open), it saves & compiles much quicker.

Testing is easy. If I am working on code for a map I typically have WC3 running in the background and alt-tab out (make sure you select a map in the map selection screen that you are NOT working on before alt-tabbing out or you will get an access violation error). Then edit your vjass code, save it, compile it, then simply alt-tab back into WC3 and test it.

Compiling Many Maps in one go
NOTE: WC3 should not be running in the background if you are going to compile a lot of maps (in case WC3 has selected one of the maps you intend on compiling - you will get an access violation error, but probably won't get a chance to see the error and thus one of your maps may not be up-to-date).

Typically you'll want to add your triggers to numerous maps. This can be done by creating a second batch file that simply calls the one you already created. Again, setting it up the first time is the most time consuming thing, but after that any time you want to update all your maps with edited triggers, it's just one command on the command line.

Create a new text file in your favorite text editor (not word processor). Create the following file contents but replace it with the actual names of the maps you want to include.

call vJassMap.bat ArcticMeltdown

call vJassMap.bat GoblinValley

call vJassMap.bat BackStab

call vJassMap.bat BridgesOfSimcoe


Then save the file as something like "vJassAllMaps.bat". Now when you want to compile source code and insert it into the above maps, just type the following on the command prompt:

vJassAllMaps

That's it! All your maps will start compiling.

NOTE: You should always make sure that you test with one map first to ensure that your code works before inserting it into all your maps. Otherwise, you'll see a slew of compile errors go by for every map being compiled, making it hard to read. Once you have your triggers working the way you want (such as spells) and tested in a test map, then compile all your maps at once.



Once you have this all set up, the process of coding, compiling, & testing is rather simple.

1. Edit your source code and save it
2. Compile it with a simple command - vJassMap mymap
3. Alt-Tab back into WC3 and test it
4. Repeat (if necessary)
 
Level 4
Joined
Nov 23, 2007
Messages
113
I suppose it's already in tutorial form but don't know the process of posting it as such.

It's not so much the highlighter in UltraEdit (although it's pretty sweet), but it's such a powerful text editor for programming in different languages (lists all my structures/functions etc with code folding). Makes my job much easier and I guess I'm just so used to it and I find it quicker to just alt-tab in/out of WC3 to test my code. Personal preference, really. But if you do a lot of programming in different languages, I suggest checking it out.
 
Status
Not open for further replies.
Top