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.
  • The Helper The Helper:
    It is online though at night
  • The Helper The Helper:
    You would probably have to take a loan to get the Rice cert it is like 14l
  • The Helper The Helper:
    I was hoping you were going to say you wanted to be a cook and wished to open up a Food Truck there are so many opportunities for that here
  • The Helper The Helper:
    you can only open the bar if you sell food and a food truck in the parking lot counts
  • The Helper The Helper:
    here in houston
  • The Helper The Helper:
    most bars are struggling to build food prep and even some I know are doing there own food trucks
  • The Helper The Helper:
    but yeah man you should come to Houston there is so much more opportunity here than San Antonio. Just look at all the homeless people on the Riverwalk and downtown there you cannot even walk down the street without getting mobbed them
  • The Helper The Helper:
    check out this place apparently it is the best roommate site out there roommates.com lol
  • Varine Varine:
    The homeless people reminded me of New York
  • Varine Varine:
    I'll check it out, my lease expires in like a few months so I need to figure something out.
  • Varine Varine:
    I tried to open a food truck in Sandpoint a few years ago but the city said no, then like two years later they passed new laws to encourage it and gave them all fucking tax breaks and shit. And at that point I didn't have enough money to go buy one so I was way too late to the game once other cities realized they could just bring their existing truck there, or sell their brick and mortar.
  • Varine Varine:
    I do like food trucks though, they're way more fun than restaurants and usually I also get some of that tip money there.
  • Varine Varine:
    Restaurants are really hard if you don't have a back up source of income to fund them sometimes, in my experience most owners either got really really lucky, had existing money that allowed them to buy an already successful one, or they have family money to fall back on for loans. It's few and far between to see very inspiring success stories where the person actually got it through hard work and perseverance. I thought about opening one lots and I always just end up not thinking it'll work. I would much rather just find someone that has that money and go work for them
  • The Helper The Helper:
    i am not talking about opening a brick and mortar I am talking about food trucks though I have seen some brick and mortar mexican places open up during covid that are doing good because there food is awesome!
  • The Helper The Helper:
    Food trucks are killing out here because Bars cannot open unless they sell food and the governor ok'd the use of a food truck in front as serving food
  • The Helper The Helper:
    Just not enough food trucks
  • The Helper The Helper:
    a buddy of mine just opened up a food truck and he is killing it but he is a great cook and has awesome food right in the middle of the pandemic too food trucks are immune to pandemic because they are take out in Texas you will always be able to get take out or delivery
  • The Helper The Helper:
    He is in the different food facebook groups in houston and posts videos of him making his food
  • The Helper The Helper:
    he is killing it
  • jonas jonas:
    @Varine with the restaurants, there surely is a lot of luck and hard work but most restaurants fail because they suck. Flair isn't right, economics not well thought through, food is mediocre or sucks, location is bad, etc. If you're thinking about opening one, make sure you're looking at the stories of those that would be playing at your level, don't let your hopes be dragged down by all the subpar restaurants out there.
  • jonas jonas:
    I'm a bit worried about the future of data science, there's an influx of incompetent people hired by incompetent managers, that can't last. But I'm sure smart data scientists will always be useful and hireable. Same as smart security people.
  • jonas jonas:
    My sister in law worked in a vegan food truck, the owners were also making a killing, added several trucks and opened two restaurants over 5 years
  • Ghan Ghan:
    The CompTIA stuff is pretty much crap unfortunately. The places that ask for those low-level certs aren't likely places you want to work. For IT you really want a degree, but in the meantime you need to figure out some way to learn the skills. Cybersecurity is really hot right now so competition is fierce.
  • tom_mai78101 tom_mai78101:
    I realized I don't have anything much to say, other than "Good luck!". Compared to other places, I'm just very lucky we didn't have a lot of surges of cases coming in.

    Members online

    No members online now.

    Affiliates

    Hive Workshop
    Top