Step 2: Open the editor and the map you want to insert your custom code into.
Step 3: Open the Script Editor (Inside Trigger Editor, Data -> View Script or Ctrl + F11) and edit it by adding an include at the top (under "include 'TriggerLibs/natives'" though). Also add to the MapInit function your initializer in the included file.
Your new MapScript.galaxy file might look like:
include"TriggerLibs/NativeLib"include"MotiveMe/Main.galaxy"//--------------------------------------------------------------------------------------------------// Library Initialization//--------------------------------------------------------------------------------------------------voidInitLibs(){libNtve_InitLib();libMotv_InitLib();// this is defined in MotiveMe/Main.galaxy!}//--------------------------------------------------------------------------------------------------// Map Initialization//--------------------------------------------------------------------------------------------------voidInitMap(){InitLibs();InitTriggers();}
Step 4: Once that's done, hit the compile button IN THE SCRIPT EDITOR. Make sure everything's up to spec! But you're not done yet!
Step 5: Hit the save button and export your MapScript.galaxy file to, for example, "MainScript.galaxy".
Step 6: Open the import manager (alternatively, you may use an MPQ editor capable of editing SC2 files for this purpose), and import the exported Galaxy file again.
Step 7: Rename the Galaxy file you just imported to MapScript.galaxy and hit save. This will overwrite the editor-generated one.
Step 8: Save and run! If you open the script editor again, your MapScript.galaxy file will be reset. Be warned.
This method is probably the best method for writing Galaxy code outside of the editor atm. You can do all sorts of powerful things with it like write half your code in GUI and the other half in Galaxy if you're smart. ;)
I've just started playing around with this, steps 1-4 I created the custom directory in the Core.SC2Mod folder any thoughts on if that's the best place?
Edit: Oh god you had to press Save in the import window itself *hides in shame*
Hi, thanks for the writeup. I'm having some issues having the editor locate my custom script, getting "Include file not found" on compilation.
The script is stored under "Lib/Script.galaxy" in my map's folder. Also tried importing the script, still can't find it. Does it need to be in some other position not relative to your map?
All includes are relative to the root dir in the MPQ. So in my example since everything is in the Cortex folder ALL of my includes (even the ones from inside Cortex) must begin "include Cortex/...".
Also, you have to hit the save button in the import manager before you can compile test accurately.
Hi, I have been trying to use this method; however, every time that I upload my files to the map with either an MPQ editor or the built-in import manager, the script files are always prefixed with a strange unicode character.
The characters that are added are the two that follow: ÿþ
I have tried using several different editors (notepad as well as many that modders have been designing specifically for SC2), and these characters never show up until the file is imported.
This drove me crazy for a while. I followed the steps too exactly and couldn't find it at all. Data, nothing. Ctrl F11, nothing. So you go and ask him where it is, which is great. I couldn't find it either. So what does the OP do? He copies and pastes what he said. No additional help. No clarification. In a live voice conversation, this would be acceptable. Maybe we didn't hear you. But we can read. Just restating what you said before without any additional information is completely useless, and aggravating.
Sorry for the rant. To find the script editor, open the Sc2Editor, open the Triggers window (F6), then open the script editor (Data ->View script) (Ctrl F11).
I've clarified on the Script Editor part. My apologies for the misunderstanding. I do not use any other part of the editor at all, so that was all I thought about.
When I import my custom galaxy file (with the F9 Import Manager, right?), I can't rename it because then all contents of that file get deleted somehow. Also I can't name the file "MapScript.galaxy" before importing it because the file does already exist (of course) when I try to import it.
Or shouldn't I use the Import Manager at all but instead an MPQ Editor?
This tutorial was written for the SC2 Beta version. Back then you weren't able to simple write code inside the editor.
Now, this is possible and this tutorial is basically obsolete.
Just open the trigger editor, right-click on the left side and select New -> New Custom Script.
This is the method I use to import my .galaxy scripts into the editor and have them work.
Step 0: Back up your map before attempting this! Really! There's a lot of potential for screwups.
Step 1: Write some galaxy code! Ideally, all your code should be in a folder like "MotiveMe" so your directory structure might look like.
Step 2: Open the editor and the map you want to insert your custom code into.
Step 3: Open the Script Editor (Inside Trigger Editor, Data -> View Script or Ctrl + F11) and edit it by adding an include at the top (under "include 'TriggerLibs/natives'" though). Also add to the MapInit function your initializer in the included file.
Your new MapScript.galaxy file might look like:
Step 4: Once that's done, hit the compile button IN THE SCRIPT EDITOR. Make sure everything's up to spec! But you're not done yet!
Step 5: Hit the save button and export your MapScript.galaxy file to, for example, "MainScript.galaxy".
Step 6: Open the import manager (alternatively, you may use an MPQ editor capable of editing SC2 files for this purpose), and import the exported Galaxy file again.
Step 7: Rename the Galaxy file you just imported to MapScript.galaxy and hit save. This will overwrite the editor-generated one.
Step 8: Save and run! If you open the script editor again, your MapScript.galaxy file will be reset. Be warned.
This method is probably the best method for writing Galaxy code outside of the editor atm. You can do all sorts of powerful things with it like write half your code in GUI and the other half in Galaxy if you're smart. ;)
where is the "Script Editor" ?
Data -> View Script (Ctrl + F11)
@MotiveMe: Go
I've just started playing around with this, steps 1-4 I created the custom directory in the Core.SC2Mod folder any thoughts on if that's the best place?
@akastar: Go
No. Use the import manager in your SC2Map MPQ file, not the SC2 MPQs.
Edit: Oh god you had to press Save in the import window itself *hides in shame*
Hi, thanks for the writeup. I'm having some issues having the editor locate my custom script, getting "Include file not found" on compilation.
The script is stored under "Lib/Script.galaxy" in my map's folder. Also tried importing the script, still can't find it. Does it need to be in some other position not relative to your map?
@Ttn114: Go
All includes are relative to the root dir in the MPQ. So in my example since everything is in the Cortex folder ALL of my includes (even the ones from inside Cortex) must begin "include Cortex/...".
Also, you have to hit the save button in the import manager before you can compile test accurately.
tutorial name is missleading, "how to make X with Y, do it in Z and import to X"
@XSharp: Go
Not really. A lot of people are using this method now successfully.
@MotiveMe: Go
You should clarify that the galaxy script files to be included need to be inside the SC2Map archive (MPQ). Maybe post a link to an MPQ Editor as well.
Hi, I have been trying to use this method; however, every time that I upload my files to the map with either an MPQ editor or the built-in import manager, the script files are always prefixed with a strange unicode character.
The characters that are added are the two that follow: ÿþ
I have tried using several different editors (notepad as well as many that modders have been designing specifically for SC2), and these characters never show up until the file is imported.
Any ideas on why this happens?
This drove me crazy for a while. I followed the steps too exactly and couldn't find it at all. Data, nothing. Ctrl F11, nothing. So you go and ask him where it is, which is great. I couldn't find it either. So what does the OP do? He copies and pastes what he said. No additional help. No clarification. In a live voice conversation, this would be acceptable. Maybe we didn't hear you. But we can read. Just restating what you said before without any additional information is completely useless, and aggravating.
Sorry for the rant. To find the script editor, open the Sc2Editor, open the Triggers window (F6), then open the script editor (Data ->View script) (Ctrl F11).
RainGame, you are such a cock. He is only trying to help. And by cock I mean your profile avatar.
I've clarified on the Script Editor part. My apologies for the misunderstanding. I do not use any other part of the editor at all, so that was all I thought about.
Thanks MotiveMe, now I can finally start coding maps!
When I import my custom galaxy file (with the F9 Import Manager, right?), I can't rename it because then all contents of that file get deleted somehow. Also I can't name the file "MapScript.galaxy" before importing it because the file does already exist (of course) when I try to import it.
Or shouldn't I use the Import Manager at all but instead an MPQ Editor?
@anteevy: Go
This tutorial was written for the SC2 Beta version. Back then you weren't able to simple write code inside the editor.
Now, this is possible and this tutorial is basically obsolete.
Just open the trigger editor, right-click on the left side and select New -> New Custom Script.
Thanks, I didn't notice that. But what if I wanted to change the MapScript.galaxy (for adding new headers e.g.)?
The methods in this tutorial still work, and it's extremely useful for including custom Galaxy libraries. I still use the same methods for my map.
But as I said, somehow the contents of the imported galaxy file get deleted when I try to rename it. :(