SC2Mapster Forums

Development > Galaxy Scripting

Script load failed: Syntax error when map starts?

    #1 Feb 19, 2012 at 15:41 UTC - 0 likes

    Hello!

    I just started scripting in the Galaxy language and I'm having some trouble with importing the files with the script inside it. I followed this tutorial to try and start, but I also made my own trigger for a spell I had in mind (just a Blink spell with some AoE damage) and I used Galaxy + + to check the syntax of the code, and there were none. And then I imported the files, and renamed it MapScript.galaxy (and then after I saved it dissapeared from the Import palette) and then I start the game, and red text appears in the bottom left saying "Script load failed: Syntax error"... ( And of course noting happens with the spell :( )

    //==================================================================================================
    //
    // <Your Map> MapScript
    //
    // Name:   <Your Map>
    // Author: <Your Name>
    //
    //==================================================================================================
    
    include "MainScript.galaxy"
    
    //--------------------------------------------------------------------------------------------------
    // Map Initialization
    //--------------------------------------------------------------------------------------------------
    void InitMap () {
        Main();
    }
    
    //==================================================================================================
    //
    // <Your Map> MainScript
    //
    // Name:   <Your Map>
    // Author: <Your Name>
    //
    //==================================================================================================
    
    include "TriggerLibs/NativeLib"
    include "Globals.galaxy"
    include "MapInit.galaxy"
    include "BurningStep.galaxy"
    include "Debug.galaxy"
    
    //--------------------------------------------------------------------------------------------------
    // Trigger: Initialization
    //--------------------------------------------------------------------------------------------------
    
    
    void InitTriggers () {
        
        //====================================================================\\
        gt_MapInit = TriggerCreate("MapInit");
        TriggerAddEventMapInit(gt_MapInit);
        //====================================================================\\
        
        //====================================================================\\
        gt_BurningStep = TriggerCreate("BurningStep_Main");
        TriggerAddEventUnitAbility( gt_BurningStep, null, AbilityCommand( "Blink", 0 ), 0, false );
        //====================================================================\\
        
        //====================================================================\\
        gt_DebugMode = TriggerCreate("DebugMode_Main");
        TriggerAddEventUnitOrder( gt_DebugMode, null, AbilityCommand( "move", 0 ) );
        TriggerAddEventUnitOrder( gt_DebugMode, null, AbilityCommand( "stop", 0 ) );
        TriggerAddEventUnitOrder( gt_DebugMode, null, AbilityCommand( "attack", 0 ) );
        //====================================================================\\
    }
    
    //--------------------------------------------------------------------------------------------------
    // Library Initialization
    //--------------------------------------------------------------------------------------------------
    void InitLibs () {
        libNtve_InitLib();
    }
    
    //--------------------------------------------------------------------------------------------------
    // Map Initialization
    //--------------------------------------------------------------------------------------------------
    void Main () {
        InitLibs();
        InitTriggers();
        InitGlobals();
    }
    
    //==================================================================================================
    //
    // <Your Map> Globals
    //
    // Name:  <Your Map>
    // Author: <Your Name>
    //
    //==================================================================================================
    
    include "TriggerLibs/NativeLib"
    
    //Objects
    
    //Triggers
    trigger gt_MapInit;
    trigger gt_BurningStep;
    trigger gt_DebugMode;
    
    // Variables
    
    //--------------------------------------------------------------------------------------------------
    // Globals Initialization
    //--------------------------------------------------------------------------------------------------
    void InitGlobals () {
    }
    
    //==================================================================================================
    //
    // <Your Map> SetupGame
    //
    // Name:   <Your Map>
    // Author: <Your Name>
    //
    //==================================================================================================
    
    include "TriggerLibs/NativeLib"
    include "Globals.galaxy"
    
    void MapInit () {
        UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, StringToText("I Has Init!"));
    }
    
    //==================================================================================================
    //==================================================================================================
    //
    // Test Map - Spell - Burning Step
    //
    // Name:   <Your Map>
    // Author: <Your Name>
    //
    //==================================================================================================
    
    include "TriggerLibs/NativeLib"
    include "Globals.galaxy"
    
    const fixed SPELL_RANGE = 50.0;
    
    //static void SPELL_DAMAGE ( unit
    
    static unit Caster = null;
    
    void UnitGroupLoop ( unitgroup uGroup ) {
        int groupNum = UnitGroupCount( uGroup, c_unitCountAll );
        
        unit u = null;
        //unitgroup grp = UnitGroupCopy( uGroup );
        
        UIDisplayMessage( PlayerGroupAll(), c_messageAreaDebug, UnitGetType( Caster ) );
        
        if ( groupNum <= 0 ) { return; }
        
        if ( groupNum == 1 ) { u = UnitGroupUnit( uGroup, 1 ); UnitDamage( Caster, null, u, 50 ); UIDisplayMessage( PlayerGroupAll(), c_messageAreaDebug, UnitGetType( u ) ); return; }
        
        while ( groupNum > 0 ) { u = UnitGroupUnit( uGroup, groupNum ); UnitDamage( Caster, null, u, 50 ); groupNum -= 1; UIDisplayMessage( PlayerGroupAll(), c_messageAreaDebug, UnitGetType( u ) ); }
        
        //return;
    }
    
    void BurningStep_Main ( bool testConds ) {
        
        Caster = EventUnit();
        
        if (testConds) {
            if (!(UnitIsAlive(Caster))) { return; }
        }
        
        //abilcmd spellAbil = EventUnitAbility();
        
        point spellPoint = EventUnitTargetPoint();
        
        point castPoint = UnitGetPosition( Caster );
        fixed castX = PointGetY( castPoint );
        fixed castY = PointGetX( castPoint );
        
        region spellRange = RegionCircle( castPoint, SPELL_RANGE );
        unitgroup spellDmgd = UnitGroup( null, c_playerAny, spellRange, UnitFilterStr( "Ground,Air,Alive;Self,Ally" ), 0 );
        
        UnitGroupAddUnitGroup( spellDmgd, UnitGroup( null, c_playerAny, spellRange, UnitFilterStr( "Ground,Air,Alive;Self,Ally" ), 0 ) );
        
        UnitGroupLoop( spellDmgd );
        
        UnitSetPosition(Caster, libNtve_gf_PointFromPositionAndAngle(spellPoint, UnitGetFacing(Caster)), true);
    }
    
    //==================================================================================================
    //
    // <Your Map> SetupGame
    //
    // Name:   <Your Map>
    // Author: <Your Name>
    //
    //==================================================================================================
    
    include "TriggerLibs/NativeLib"
    include "Globals.galaxy"
    
    const bool DEBUG_MODE = true;
    
    void DebugMode_Main () {
        abilcmd ab = EventUnitAbility();
        unit u = EventUnit();
        order o = EventUnitOrder();
        
    	if DEBUG_MODE {
    	    UIDisplayMessage( PlayerGroupAll(), c_messageAreaDebug, AbilityCommandGetAbility( ab ) );
    		UIDisplayMessage( PlayerGroupAll(), c_messageAreaDebug, AbilityCommandGetAbility( OrderGetAbilityCommand( o ) ) );
    	}
    }
    

    Those are all my triggers atm and I'm really sorry to ask this question but, what inside those could cause trouble ? :S

    Last edited Feb 19, 2012 by Komaqtion
    #2 Feb 19, 2012 at 16:23 UTC - 0 likes

    What does the syntax error message say?

    I suspect it may be because you are including Global.galaxy multiple times. Since your Global.galaxy file appears to declare some triggers, by including it multiple times, the compiler attempts to declare those trigger variables multiple times. In C, if two variables in the same scope (Global with global or local with local) have the same name it will cause a syntax error.

    Last edited Feb 19, 2012 by FuzzYD
    Works
    AoS2
    Coder
    Boss Bars+
    Custom boss bars
    GXML
    Dialog XML parser
    Project W
    Coder
    RandNAligning dialog labels

    #3 Feb 19, 2012 at 17:43 UTC - 0 likes

    The syntax error says nothing... It only says "Script load failed: Syntax error", that's it.

    But I'll try out that solution, and that means taking away the "include Globals.galaxy" line in those other files, except in the "MainScript.galaxy file, or what?

    #4 Feb 19, 2012 at 18:24 UTC - 0 likes

    In your last file, you have an if without parenthesis.. that wouldn't be valid in galaxy++ either.

    Also, in same file, you use UIDisplayMessage with something of type string passed in last argument. In galaxy, you would have to convert it to a text.

    Last edited Feb 19, 2012 by SBeier
    #5 Feb 19, 2012 at 23:46 UTC - 0 likes

    First, thanks, didn't see that... And I now convert it from string to text, but now nothing in the triggers happen when I start the game, not the "I has init" string or anything. (Not that it did so before, but now there isn't the "Syntax error" text at least).

    #6 Feb 20, 2012 at 01:36 UTC - 0 likes

    @Komaqtion: Go

    Looks through your code, It appears you call a function Main(); in InitMap, but I don't see that function in any of your other files. Guessing from context the Main() file here would have been the one to invoke the functions in every other included .galaxy you have. Could you post the script for your Main(); For us to take a look?

    Ignore that, overlooked it.

    I noticed the triggers you created do not follow the basic trigger format. Trigger functions typically have the following structure. This might be the root cause of the problem.

    bool MyTrigger (bool tc, bool ra){
        //Vars
    
        //Conds
    
       //Actions
    
        return true;
    }
    

    Your MapInit function for example is of type void. Try changing it to bool MapInit( bool tc, bool ra){ return true;} and see if it works? If it does then it confirms the theory posted above. So try the same with the other triggers you initialized.

    Other things to note:

    • There appears to be redundancy in including the NativeLib library in your files, you could probably do without it.

    MapInit() could also be invoked as a function call rather than a trigger. By using it as a function call you won't need these lines:

    trigger gt_MapInit;
    . . . . .
        gt_MapInit = TriggerCreate("MapInit");
        TriggerAddEventMapInit(gt_MapInit);
    

    Just directly invoke it in your Main()

    The pro of this is you don't need the extra trigger variable. In large scale projects, having too many triggers that are created and just left in the memory might significantly reduce the amount of memory you have to work with from the 2MB limit.

    The con is, your script executes sequentially. So if you have a lot of stuff at initialization without triggers, is going to increase your map load time. The reason you see Blizzards generated script using triggers for map initialization is that they create a thread whenever their event fires. So it all executes in parallel.

    There is a galaxy function somewhere out there from s3rius that allows you to do a one time function run without the need for a useless trigger variable sitting in memory. How it works is that you call the function by it's string name, The trigger is created, run, then destroyed.

    void tRun( string s);
        trigger t = TriggerCreate(s);
        //Run the trigger here, Don't wait for execution to complete
        TriggerDestroy(t);
    }
    
    Last edited Feb 20, 2012 by FuzzYD
    #7 Feb 20, 2012 at 10:22 UTC - 0 likes

    I've worked quite alot with triggers (JASS/vJASS) in WC3 before, so I know alot of the mechanics in triggers and such, but thanks anyway :D But in WC3 you could include (requires/uses/needs were the commands then IIRC) the same script as many times as you wanted, in different triggers of course. But here you only need to include them in the first file then, MapScript, since they all en up in the same file anyway, right?

    And for the bool MyTrigger instead of void MyTrigger, I got errors in Galaxy+ + when I did the bool thing, which is weird since I know it should work that way, but I decided that I would just go with void instead. But I'll try bool again ;)

    Last edited Feb 20, 2012 by Komaqtion
    #8 Feb 20, 2012 at 10:32 UTC - 0 likes
    Quote from Komaqtion: Go

    I've worked quite alot with triggers (JASS/vJASS) in WC3 before, so I know alot of the mechanics in triggers and such, but thanks anyway :D But in WC3 you could include (requires/uses/needs were the commands then IIRC) the same script as many times as you wanted, in different triggers of course. But here you only need to include them in the first file then, MapScript, since they all en up in the same file anyway, right?

    Using include multiple times is not required, but shouldn't cause any errors, either

    Quote:

    And for the bool MyTrigger instead of void MyTrigger, I got errors in Galaxy+ + when I did the bool thing, which is weird since I know it should work that way, but I decided that I would just go with void instead. But I'll try bool again ;)

    Plain galaxy requires a function with 2 boolean parameters and a boolean return type to work as a trigger function. Galaxy++ supports void as well and adds the specifications internally. It shouldn't cause errors for valid plain Galaxy syntax, though.

    Last edited Feb 20, 2012 by Kueken531

    http://img577.imageshack.us/img577/4226/blaj.jpg

    #9 Feb 20, 2012 at 11:00 UTC - 0 likes

    Ok, well I still removed all requires from all other triggers except MapScript and MainScript, but still no results... And I made all trigger-methods/functions bool, and added two bool parametres to them also :S

    Dunno what else it could be...

    #10 Feb 20, 2012 at 12:09 UTC - 0 likes

    @Komaqtion: Go

    are you open to the idea of attaching your map here so we can take a look? this is truly a wierd one.

    #11 Feb 20, 2012 at 15:41 UTC - 0 likes

    Sure :D No problems, since it's just a test map :D

    Here it is ;)

    #12 Feb 20, 2012 at 15:52 UTC - 0 likes

    Is it just me, or is the MainScript.galaxy file missing in the map?

    You need to import the file into your map, either with the import manager or with an MPQ editor; it cannot include files in some folder of your computer.

    Last edited Feb 20, 2012 by Kueken531
    #13 Feb 20, 2012 at 16:11 UTC - 0 likes

    Hmm, now that I opened the map myself, there were no files imported at all :S I'll upload it again XD (Still doesn't work btw :S)

    https://rapidshare.com/files/2449216894/Testing.SC2Map

    #14 Feb 21, 2012 at 02:51 UTC - 0 likes

    @Komaqtion: Go

    Had to add a custom script into the triggers to get this working. Modified a few of your galaxy scripts as well because the compiler was spewing errors. (Mostly unexpected return value). I commented the changes made in the attached .galaxy files.

    Reason why it wasn't working was that MainScript.galaxy was never being included. If you go to triggers and press Ctrl+F11, the only thing there was include TriggerLibs/natives and a generated InitMap() function. Thus the problem was fixed by manually including MainScript.galaxy in a custom script, then setting the start point by defining Main as the initializer function (See the bottom of the custom script).

    Take a good look at the changes made, It'll help you understand what went wrong. Normally I would just guide you to solve the problem, but in this case its quite hard for me to explain it without fixing it. @_@

    @Kueken531: Go

    Nice teamwork, we pretty much took turns on this one :P

    Last edited Feb 21, 2012 by FuzzYD
    Name Size MD5
    Fun.rar 10.6 KiB d4c35544f2aa...
    #15 Feb 21, 2012 at 14:24 UTC - 0 likes

    Ok, thank you soo much :D But it's still a bit weird that you had to go to such lengths to make this work :S It shouldn't be like this, right ?

    And what compiler spewed out errors? The default Galaxy compiler? What were the unexpected return values? Those questions are just to make me understand the whole process more :D You don't have to answer them :P

    Anyways, thank you all so much for helping me with this ;)

    #16 Feb 21, 2012 at 14:28 UTC - 0 likes

    If you press Ctrl + F11, you always see the generated script by the triggers in the trigger editor. However, he imported a custom MapScript.galaxy, which included the MainScript.galaxy and used a custom InitMap function calling the Main function. You can have a look at this imported mapscript in the import-manager, if you check show reserved files.

    I cannot check the map right now, but did you include the NativeLib? By default only the natives is included, NativeLib contains some other functions, which also need to be included; however it is only done automatically, if you use at least 1 Gui trigger.

    Last edited Feb 21, 2012 by Kueken531
    #17 Feb 21, 2012 at 17:18 UTC - 0 likes

    @Komaqtion: Go

    And what compiler spewed out errors? The default Galaxy compiler?

    Yeah, the Galaxy compiler, or syntax checker? I've heard somewhere galaxy compiles at run time so it might be the syntax checker here.

    What were the unexpected return values?
    Oops, made a mistake here, I meant "Expected return values"

    You had some functions of boolean type (Triggers) that did not have a "return true;" statement at the end of it. So the syntax checker spit out an errors that said expected return value.

    But it's still a bit weird that you had to go to such lengths to make this work :S It shouldn't be like this, right ?

    Not to worry, always happy to spread the love to those who wish to learn galaxy <3 lol

    @Kueken531: Go

    However, he imported a custom MapScript.galaxy

    Hmmm.. didn't notice this, theoretically, that should have worked. Not sure why it didn't.

    I cannot check the map right now, but did you include the NativeLib?

    I'm recalling from memory that I didn't see it. But then again, I didn't notice the MapScript.galaxy override. Will try take a look at it again tomorrow out of curiosity.

    Last edited Feb 21, 2012 by FuzzYD
    #18 Feb 21, 2012 at 21:56 UTC - 0 likes

    Ok, so your map doesn't work for me :( Or at least the spell doesn't work, and the MapInit message isn't showing either...

    I'll upload all my files with the galaxy script in them here, and also your map (with some changes by me).

    https://rapidshare.com/files/3736379486/Testing_-_Helped.SC2Map

    https://rapidshare.com/files/4059450669/BurningStep.galaxy

    https://rapidshare.com/files/1902007730/Debug.galaxy

    https://rapidshare.com/files/877631424/First_script.galaxy

    https://rapidshare.com/files/3697056212/Globals.galaxy

    https://rapidshare.com/files/3478523590/MainScript.galaxy

    https://rapidshare.com/files/563003663/MapInit.galaxy

    The file "First script" is the one I later rename to MapScript.galaxy after I've imported it ;)

    Last edited Feb 21, 2012 by Komaqtion
    #19 Feb 23, 2012 at 07:39 UTC - 0 likes

    @Komaqtion: Go

    Sorry I couldn't respond yesterday. Net was down. Will take a look when I'm able. Strange.. when I tried it the other day It was working fine. There were little explosions wherever I targeted the spell.

    Btw, please attach files to your post next time, it can be done through the edit feature. File sharing websites tend to have all sorts of junk all over these days so I find it rather cumbersome to use them =/

    Last edited Feb 23, 2012 by FuzzYD
    #20 Feb 23, 2012 at 11:17 UTC - 0 likes

    Oh right XD I haven't told you what the spell is suppoed to do yet, haha :P

    It's like Blink, you teleport to the target, and deal some damage :D Simple spell, which I know can be done in the Data Editor, but I feel more comfortable with triggers, and I can't seem to understand the Data Editor much so it's simpler like this ;)

    And also, I have the MapInit function which is supposed to output a message at map initialization, which it still doesn't... :(

    But thank you so much for all your help so far :) Just need a little more and then I'll have a working map to start coding a bit more with.

You must login to post a comment. Don't have an account? Register to get one!