Tutorial Galaxy - How to Script in Galaxy (Easily)

Sevion

The DIY Ninja
Reaction score
413
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

  • Galaxy.7z
    26.5 KB · Views: 811

The Undaddy

Creating with the power of rage
Reaction score
55
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
Reaction score
31
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
Reaction score
413
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
Reaction score
31
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
Reaction score
413
You only have to export once and that's if you already have code. Importing is just Control + I, Enter, Enter, Control + F9.
 

Im_On_56k

Hm...
Reaction score
116
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
Reaction score
31
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
Reaction score
154
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
Reaction score
413
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
Reaction score
62
> "To attach data to timers, you could just..... Parallel arrays? Idk. I'll have to look into that."

Did you see anything?
 

GooS

Azrael
Reaction score
154
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
Reaction score
413
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
Reaction score
413
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
Reaction score
154
Yes they all exist and are imported and I've checked over the scripts and there shouldn't be a problem with them
 

GooS

Azrael
Reaction score
154
Yep. That should do it.

Sorry, They are in root, was just to fast when checking >.<

Tested making a complete replica of your files, didn't work either, dang :/
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top