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: 821

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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top