Tutorial Galaxy - How to Script in Galaxy (Easily)

Sevion

The DIY Ninja
Yes... It's finally here... A tutorial... From me... With a billion "..."'s...

Anyhow, let's get started.

No big titles, they're unnecessary <3

First, you should get your favorite text editor. Mine is Notepad++ for its easy syntax highlighting and other features.

(Note, if you use Notepad++, there will be syntax highlighting AND autocomplete attached to the bottom of this post! :3)

Next, you want to have your map opened to the Import Manager. Or whatever it's called... I never bothered to memorize the name of the window.

After you have that up, make a .galaxy file in your text editor (named WHATEVER YOU WANT with a .galaxy extension)

Once you have that, input this code:

JASS:
//==================================================================================================
// 
// &lt;Your Map&gt; MapScript
// 
// Name:   &lt;Your Map&gt;
// Author: &lt;Your Name&gt;
// 
//==================================================================================================
include &quot;MainScript.galaxy&quot;

//--------------------------------------------------------------------------------------------------
// Map Initialization
//--------------------------------------------------------------------------------------------------
void InitMap () {
    Main();
}


Yes, it NEEDS to be [ljass]"MainScript.galaxy"[/ljass] because it'll be used later on. Though, you CAN change it to whatever you want. Just remember to change the file name later on as well.

Now, for the later on... Make the MainScript.galaxy file and put in this:

JASS:
//==================================================================================================
// 
// &lt;Your Map&gt; MainScript
// 
// Name:   &lt;Your Map&gt;
// Author: &lt;Your Name&gt;
// 
//==================================================================================================
include &quot;TriggerLibs/NativeLib&quot;
include &quot;Globals.galaxy&quot;

//--------------------------------------------------------------------------------------------------
// Trigger: Initialization
//--------------------------------------------------------------------------------------------------

void InitTriggers() {
}

//--------------------------------------------------------------------------------------------------
// Library Initialization
//--------------------------------------------------------------------------------------------------
void InitLibs () {
    libNtve_InitLib();
}

//--------------------------------------------------------------------------------------------------
// Map Initialization
//--------------------------------------------------------------------------------------------------
void Main () {
    InitLibs();
    InitTriggers();
    InitGlobals();
}


Good! Now you have the file down! Next, make a Globals.galaxy file.

Put in this:

JASS:
//==================================================================================================
// 
// &lt;Your Map&gt; Globals
// 
// Name:  &lt;Your Map&gt;
// Author: &lt;Your Name&gt;
// 
//==================================================================================================
include &quot;TriggerLibs/NativeLib&quot;

//Objects

//Triggers

// Variables

//--------------------------------------------------------------------------------------------------
// Globals Initialization
//--------------------------------------------------------------------------------------------------
void InitGlobals () {
}


Good! All of your basic files are done!

After all of your basic files are done, you can now start scripting! Make your script file... I.E. if you want to SETUP your GAME, name it something like SetupGame.galaxy.

JASS:
//==================================================================================================
// 
// &lt;Your Map&gt; SetupGame
// 
// Name:   &lt;Your Map&gt;
// Author: &lt;Your Name&gt;
// 
//==================================================================================================
include &quot;TriggerLibs/NativeLib&quot;
include &quot;Globals.galaxy&quot;

bool SetupGame ( bool testConds, bool runActions ) {
    //Dew Stuffz
    UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, StringToText(&quot;I Has Init!&quot;);
}


Then, in the triggers section in Globals.galaxy, add your trigger:

JASS:
//Triggers
trigger gt_SetupGame


Include the file in MainScript.galaxy:

JASS:
//==================================================================================================
// 
// &lt;Your Map&gt; MainScript
// 
// Name:   &lt;Your Map&gt;
// Author: &lt;Your Name&gt;
// 
//==================================================================================================
include &quot;TriggerLibs/NativeLib&quot;
include &quot;Globals.galaxy&quot;
include &quot;SetupGame.galaxy&quot;


Initialize it in MainScript.galaxy:

JASS:
void InitTriggers () {
    gt_SetupGame = TriggerCreate(SetupGame);
    TriggerAddEventMapInit(gt_SetupGame)
}


Lastly, import them ALL into your map via Import Manager and rename the very FIRST script you made to MapScript.galaxy. Replace the existing one. Save. (Yes, you have to rename. It won't let you import files with reserved names but will let you rename to those.)

Yay! Now, all you have to do is script and be sure to initialize them in the script files. You don't HAVE to follow these conventions, but I like them and they're easy if you have a tabbed text editor (Notepad++!!!!).

Now, for my uber sexy highlighting and autocomplete:

Mini-Tutorial:

Download the attachment and un7z it. Place Galaxy.xml into $ProgramFiles$\Notepad++\Plugins\Apis\

Open Notepad++ and go to View -> User Defined Language Dialog.

Import a new language and select Galaxy Highlighting.xml.

I have some presets in there set to match the Dark Blue theme. Change the settings as you see fit, but for the love of God, don't change anything but colors.
 

Attachments

The Undaddy

Creating with the power of rage
Thanks a lot for this <3 Finally I can organize my stuff. But what do I do if I already have loads of triggers in my map made in the GUI. I kinda want to extract them and modify variables and stuff. Also, must variables start with lv_ or gv_ and then a lowercase letter, or is it just made for the GUI to work properly?

Edit: On a somewhat related note, how do I attach data to timers?

Edit2: Yet again, on a somewhat related note (but more so than the previous) , do I have to copy my entire map script before adding my 'custom made one' so as not to lose it (the original)? Libraries included?
 

Arkless

New Member
Could you give me a reason why this is better than just using the built in custom script option? (right click where your gui triggers/folders/variables are => new => custom script)
It can be organized in all those folders, wich I think is prett cool^^.
You can still declare variables everywhere in the code and add an "include <library>", it also offers to call a custom initialization function (on the very bottom under your script).
 

Sevion

The DIY Ninja
Thanks a lot for this <3 Finally I can organize my stuff. But what do I do if I already have loads of triggers in my map made in the GUI. I kinda want to extract them and modify variables and stuff. Also, must variables start with lv_ or gv_ and then a lowercase letter, or is it just made for the GUI to work properly?

Edit: On a somewhat related note, how do I attach data to timers?

Edit2: Yet again, on a somewhat related note (but more so than the previous) , do I have to copy my entire map script before adding my 'custom made one' so as not to lose it (the original)? Libraries included?
You'd just have to View Script and save it to a file. variables do not have to be prefixed. This is just a fix for "ghosting" variables (as seen in pre-1.22a WC3).

To attach data to timers, you could just..... Parallel arrays? Idk. I'll have to look into that.

Yes you would.

This is better because you can have better syntax highlighting, code completion, non-laggy typing (yes the editor is laggy, don't preach about how it's not please). And it CAN be organized. My folders are setup like this:

JASS:
Element TD
      - Element TD.SC2Map
      - Scripts
            - Map.galaxy
            - MainScript.galaxy
            - SetupGame.galaxy
            - Globals.galaxy
            - &lt;Some other SVN files&gt;
 

Arkless

New Member
This is better because you can have better syntax highlighting, code completion, non-laggy typing (yes the editor is laggy, don't preach about how it's not please). And it CAN be organized.
Well, sometimes it does not highlight, screw it, whenever I tpye the next char it does again. So no problem there.
Code completion is nice, but not worth the trouble of exporting/importing (in my opinion). I like ctrl+F9 every few minutes.
Laggy? I never experienced lagg while typing galaxy script, might be because I didn't do much till now, if I find out it really lags then I will probably use notepad++ too :p.
I think organizing it with folders + subfolders is good enough.

I didn't mean to make it sound bad, I just wanted to know the advantages ^^
 

Sevion

The DIY Ninja
You only have to export once and that's if you already have code. Importing is just Control + I, Enter, Enter, Control + F9.
 
Laggy? I never experienced lagg while typing galaxy script
You're right the sc2 editor does a great job of parsing one line of code with little to no delay.

But...when the script has more than one line I have developed a script to predict the anticipated waiting time for it to parse everything.

This is in pseudocode, but the results are found to be around the range of 99-102% correct.

Code:
real waitTime = 0.1

if ScriptGetLines() > 1 then
 waitTime += ScriptGetLines()^11
end if
if Random(1,243) <= 242 then
  waitTime *= 3
end if
if LastSaveTimeMinutes() >= 15 && ScriptGetLines() > 23 then
  Crash()
end if
Wait(waitTime)
 

Arkless

New Member
Right now I am only working as a data editor but it seem like I have to find a better editor (some user made stuff) or just use notepad++ as soon as I go back to using the trigger editor :p
 

GooS

Azrael
Oh my sweet science, wtf is my editor doing, I do not know...

Anyways, when importing, the import works, when renaming my editor magically grabs a random script from the imported ones and puts it in MapScript.galaxy, I've retried roughly 10 times in case of missclick, but truly, the editor is a sorcerous being to be reckoned with!

I have no idea how, why and what is going on, but to describe my problem shortly: I can't rename my randomy named file to "MapScript.galaxy", as a note the editor does not ask me if I want to replace the MapScript already present.

Anyways, anyone having similar problems or know what I'm doing wrong or what is wrong?
 

Sevion

The DIY Ninja
The only thing I can say is try deleting all imported files and import only the randomly named file and do the renaming.

Else, we can TeamViewer it. Pop me a reply if you're wanting to try that.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
> "To attach data to timers, you could just..... Parallel arrays? Idk. I'll have to look into that."

Did you see anything?
 

GooS

Azrael
The import part is now working, when importing only the mapscript first, renaming it, then importing the rest. However the scripts don't seem work, dont even try to run when the map is started. Hmm, gonna check through all scripts and see If something differs in my scripts that makes everything fail!
 

Sevion

The DIY Ninja
Can you upload them in a pastebin? Or do you want to use TeamViewer some time? I'm free almost all day today. Just have to stop over at the school to drop off my supplies and then I'm done with anything else. Though, I'll probably be screwing around on Garry's Mod making engines... :-/

@Sgqvur Not really. Though I did see something like Data Tables. Didn't look into it though. Maybe you could. (I find figuring out things is easier in GUI and then covert it to Galaxy! After you know what each function does in Galaxy (and what it is in Galaxy) it's much easier because you have your trusty autocomplete! :3)
 

Sevion

The DIY Ninja
Do all of these exist?

JASS:
include &quot;initializeAll.galaxy&quot;
include &quot;settingController.galaxy&quot;
include &quot;setSettings.galaxy&quot;
include &quot;waveController.galaxy&quot;
include &quot;lboardController.galaxy&quot;
include &quot;waveAdapter.galaxy&quot;
include &quot;creepController.galaxy&quot;
include &quot;defenseScore.galaxy&quot;
include &quot;creepGoal.galaxy&quot;
 

GooS

Azrael
Yes they all exist and are imported and I've checked over the scripts and there shouldn't be a problem with them
 
General chit-chat
Help Users
  • No one is chatting at the moment.

    Staff online

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top