Advanced Macro & Recipes

From SeriousEngine.com

(Redirected from Advanced Macro)
Jump to: navigation, search

Contents

Sending events

Sending Events is helpful if you want to trigger of an event, which is started when the event is sent. Sending events can be a big ease for every macro. But don’t capitulate now! Sending events sounds complicated but it isn’t after you got some practice. Look on this code example:

Image:00_00_firstpart.jpg

This is the whole stuff required to send events. It is only a small simple code line. Really easy, isn’t it? Ok, here is the “translation” of the macro code so far:

1. The “Wait (false)” should be put in on top of the most macros, to keep the macro alive after running through it. Otherwise it will be passed only once and then it’s off.

2. Then, the “On (event(Detector.Activated))“ queried if the detector is activated, then send the event called “This.DetectorIsActivated” where “This” is the current macro and “DetectorIsActivated” is a name which you can call different, too.

This has made the event “DetectorIsActivated” to be sent to the current macro. You can replace “This” with any other name. For example, you can use e.g. “Control” instead of “This”, but then make sure that the macro, which should represent the “Control”, is dragged onto the “Control” (in red), which becomes “Control” (in green) after dragging the macro onto it.

Then, you may go on with something like that:

Image:00_01_secondpart.jpg

After the event “DetectorIsActivated” was sent, you shall query the event in either an “On event” or “Wait event” function, to set the events which shall happen after the event was sent. In this example, after the event is sent, the game will spawn some enemies. Every combination is possible, but limited to the limitations of the SEd2 macro language. For the name of the sent events, there aren’t any limitations. You can use every name you want.

Running/link to other macros

Running/linking other macros can be helpful if a code block shouldn’t autorun, it is better if it is started. To achieve this, you can use the “Run” or “RunAsync” command:

Image:01_00_firstpart.jpg


Explanation:

1. After the Detector has been activated, run the “DetectorActivated” Macro in This.

2. This will jump the “DetectorActivated” macro, which can contain the same as in every macro.

Note: You can use the “RunAsync” command, too. This won’t wait until the targeted macro is complete to continue with the next commands. You can use other macro’s instead of “This”, too. But then make sure that you drag the desired macro onto the variable in order for it to work.

Variables: Setting up & using

Variables are very versatile in their way to be used. First, I'll explain some basics.

1. Variable names are case-sensitive. This means, if you name a variable "Test", "tEst" won't work.

2. In special cases, you cannot use variable type #1 and fill in variable type #2. For example: You cannot use an INDEX variable to fill in a String. This causes errors. But the other way round, an INDEX variable in a CString - that will work.


Ok, these should be the most common basics. Now I will show you how you can simplify your macro:

Every macro should be easy to understand, not only for those who write them, but also for those who edit them. In this case, you should do "refactoring" wherever possible. "Refactoring" means to simplify the code as strong as it is possible. These are some steps for factorizing:

1. Use variables instead of hard numbers/words (explained below)

2. If you are going to use copy & paste, you should copy the block once and put it into an own macro. Then you use the "Run" or "RunAsync" commands.

3. Comments are allowed; in fact, you should always write comments ("//"), or you may forget what the code is for. But you shouldn't use the comments-overkilled. Because each macro needs not less drive space and every KByte that can be saved should be saved.


Ok, these are the most important steps for refactoring; I gave them to you only for completeness. Now let's start with macro using. In the following macro code examples, the steps 1,2 and 3 of refactoring are used. But don't panic, I will explain what I've done.

Image:04 00 one.jpg

Ok, here is the explanation:

- The ItemCount variable is increased by 1 (you can set 2, 5 or even 6378385) each time one Item is picked. Note: If you are doing this, you have to select ALL Items and drag them onto the Item variable, which becomes green after succesfully dragging. This has to be repeated each time you want to add more items to the Item variable. Select all Items you want to be queried and drag them onto the variable.

- Step 2 of refactoring is used by the second } On(event... statement. Instead of writing...

Image:04 01 two.jpg

we write

Image:04 02_three.jpg

This simplifies the macro code, because otherwise each time you add more items, you have to edit the ItemCount== and set the max items after the ==. I know it isn't really space saving, but it does simply the macro, you will see! Now as the comparison for the ItemCount variable, the MaxItems variable is used, using the value we've set above.

- The rest of the macro shouldn't be hard to understand, it follows the regular rules of programming a macro.

I know, it sounds a bit complicating, I know how it is. But after you've tried it out in a practical example, you will see that it only sounds complicated.

Recipes for various & repetitive aims

While programming macros, you may quickly get, that there are many repetitive things which are used in nearly all levels. In this section, I’ll give you some of the most used code-recipes, which you can use in your level in order to speed up the coding process. I also give you some exotical recipes which aren't used often. Please note that all recipes are currently unsorted.

Topics:

1. Setting up a boss

2. Setting up a timer

1. Setting up a boss

You may get to the point of wanting a special challenge in your level(s). No problem – you may place a boss in your level. Setting up a boss is quite easy. First, here is the complete macro needed to set up a boss. The macro will be explained below.

Image:02 00 firstpart.jpg

Explanation: This is the complete macro. It looks complicated, but it really isn’t. Translation:

1. You have to set up a variable in order to get bosses working. You don’t need to declare a variable for this. You need to select the WorldInfo entity (press N) and drag it onto the red "WorldInfo" variable. The "WorldInfo" becomes green after successfully dragging on it.

2. Action WorldInfo.RegisterBoss(Boss,”Your Boss Name”): This command line is the core of the boss macro. It will say the WorldInfo entity that there is now a boss on screen. This causes in giving the enemy, which has become a boss, a health bar. The best thing is trying it out – it isn’t that hard as it sounds.

If you made everything correct, if you press T (test mode), you should see a bar appearing on top of the screen:

Image:02 01 inaction.jpg

That's it! That's all you need to know in order to set up a boss. If you now attack him, his health bar reduces by the amount of damage you inflictet to him. Happy trying out :)!

2. Setting up a timer

If you like creating a challenge for your level’s players, you may use timers, like they are used in Croteam’s “Be Quick Or Be Dead”, “Welcome to the Jungle” etc. levels. The best thing is, that you can use it for everything you want. Nothing blocks your imagination of the usage of the timer! Be creative! I’ll show you a simple example how to use the timer. I’ll use the timer in this example to query if the player has killed an enemy within a time period of, let’s say, 60 seconds. If the period has expired, nothing will happen. If the player has killed the enemy within 60 seconds, a reward will be given. Please note, that, to achieve this, variables are needed. Without them nothing works. But there’s no need to desperate, if you tried this live in your SEd2, you will see that it isn’t that hard to understand. Ok, now proceed to the macro.

Image:03 00 firstpart.jpg

Explanation: The only thing worth to explain is the if-query. The minus 1 (-1) means that the timer ran out (to zero), so the time was over. If that happens, there will no reward occur; the player has to try it again faster in order to get the reward ;). It really is very easy, try it out by yourself. You will see! :)

And please note, that this example isn't very usability-approved. In order to change the period, you have to edit each value (so if you set 120 instead of 60, you need to change all 60 values to 120). But for this, it is ok.

So, here is the working timerbar on the screen:

Image:03 01 timerbar.jpg

And here you can see what's happening if you kill the enemy within these 60 seconds:

Image:03 02 killedwithin60.jpg

And here is what happens/not happens if you need too long for killing an enemy:

Image:03 03 killedbeyond60.jpg


Made by: Knight_Christian

Personal tools