Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2013-02-07 02:48:16

tysonrss
Member
From: US, Ohio
Registered: 2011-08-27
Post 546/649

Triggers

I have never really had a firm understanding of triggers, at best all I knew was that the map had to be in the trigger table (0x94000)but that's about it.

Tawausser wrote:

[[Number1 of pointers] Number1 * [2byte pointer to script][00][00]][[Number2 of pointers] Number2 * [Number][2byte pointer to script]]

I'm afraid that's where things get complicated for me. Sure it's explained but I still can't understand it lol.

I know in the map script there has to be a pointer, but I don't understand what the pointer is supposed to point to. To avoid any other confusion, could someone further explain this? I'm sure it will be helpful for newbies who are interested at well.


Pokemon Blue DX is reborn!

Offline

#2 2013-02-07 07:41:01

Miksy91
Member
Registered: 2010-10-16
Post 1,506/2,311

Re: Triggers

It's written so that "Number1" defines how many pointers you have for the First Part and "Number2" for how many for Second Part. They are not in [] so they're not actual data like the rest. Instead, they're there for telling that if you for instance have [Number1 of pointers] set as 02, you will have 2 times [2byte pointer to script][00][00] following it. If [Number1 of pointers] is set to 00, you have 0 times [2byte pointer to script][00][00] following it (in other words, the Second Part starts right away after the [Number1 of pointers] which is 00).

For Second Part, [Number2 of pointers] determines how many different scripts you're going to call, set this either to 00 or 01 for conveniece (explained below). [Number] stands for one of the numbers between 01 and 05 referring to "Status of map", and finally you have [2byte pointer to script] following it. And just like with First Part, by setting [Number2 of pointers] to 00, nothing is being called from here and no more bytes follow that one.

One of these could be the map's script for a map that is "unique" in its own way (by having something being called from the map's script header):

00 01 05 XX XX // 01 is the beginning of Second Part
03 XX XX 00 00 YY YY 00 00 ZZ ZZ 00 00 00 // Final 00 is the Second Part
02 XX XX 00 00 YY YY 00 00 01 02 ZZ ZZ // 01  is the beginning of Second Part

You really never need to have "Number2" being set to anything higher than 1 (in this example it is 1 or "01") and so call two scripts from the Second Part. You can simply call one and make it check whether certain bit values are set or not and call different kinds of things based on them.

Last edited by Miksy91 (2013-02-07 07:49:23)

Offline

#3 2013-02-07 08:00:48

comet
Member
Registered: 2012-04-09
Post 122/674

Re: Triggers

So map script headers have two types of data. Triggers are run once when you enter the map. Callbacks are run more or less once a frame.

An example map script header would look like this:

IndigoPlateauPokeCenter1F_MapScriptHeader: ; 0x180000
    ; trigger count
    db 1

    ; triggers
    dw UnknownScript_0x180009, $0000

    ; callback count
    db 1

    ; callbacks

    dbw 5, UnknownScript_0x18000a
; 0x180009

UnknownScript_0x180009: ; 0x180009
    end
; 0x18000a

UnknownScript_0x18000a: ; 0x18000a
    domaptrigger GROUP_WILLS_ROOM, MAP_WILLS_ROOM, $0
    domaptrigger GROUP_KOGAS_ROOM, MAP_KOGAS_ROOM, $0
    domaptrigger GROUP_BRUNOS_ROOM, MAP_BRUNOS_ROOM, $0
    domaptrigger GROUP_KARENS_ROOM, MAP_KARENS_ROOM, $0
    domaptrigger GROUP_LANCES_ROOM, MAP_LANCES_ROOM, $0
    domaptrigger GROUP_HALL_OF_FAME, MAP_HALL_OF_FAME, $0
    clearbit1 $0309
    clearbit1 $030a
    clearbit1 $030b
    clearbit1 $030c
    clearbit1 $030d
    clearbit1 $030e
    clearbit1 $030f
    clearbit1 $0310
    clearbit1 $0311
    clearbit1 $0312
    clearbit1 $05b8
    clearbit1 $05b9
    clearbit1 $05ba
    clearbit1 $05bb
    clearbit1 $05bc
    setbit1 $075f
    return
; 0x180053

The trigger is commented out. Maybe it used to do something. It probably contained what is now the callback, but maybe it didn't work properly. I don't know.

What we do know is that the callback makes sure that being in the Indigo Plateau pokecenter resets all the Elite Four rooms and variables (that's what the triggers do).

I had to look this up in main.asm to know what you were even talking about because the 'Number1' 'Number2' designation was so confusing.

e: presumably the $0000 is an optional parameter.

Last edited by comet (2013-02-07 08:39:55)

Offline

#4 2013-02-07 20:21:02

tysonrss
Member
From: US, Ohio
Registered: 2011-08-27
Post 547/649

Re: Triggers

Lol I must be really dumb because I still don't get it.

What I've done is basically put the map into the trigge table, then write the script and using the deactivate command 01 to obviously deactivate the trigger and that's all. The script is a regular old script, mom comes to you, name the rival and then gives you an item and sets a bit, deactivating it with the command.

I have no followed that "guideline" at all and I'm thinking I dont have to...

Last edited by tysonrss (2013-02-07 20:22:02)


Pokemon Blue DX is reborn!

Offline

#5 2013-02-07 20:54:14

Tauwasser
Member
Registered: 2010-10-16
Post 340/448

Re: Triggers

Miksy91 wrote:

You really never need to have "Number2" being set to anything higher than 1 (in this example it is 1 or "01") and so call two scripts from the Second Part. You can simply call one and make it check whether certain bit values are set or not and call different kinds of things based on them.

Actually, that's pretty terrible advice! Check out Map Loading processes to know why. Basically, you cannot just call one script, because a) it might not be executed in all modes the map can be entered in, e.g. start from title screen, after fight etc.; b) the data you may try to edit might not be loaded: you cannot edit the tileset in 0x01 type scripts, for instance, because it isn't there yet!. See Script Header.

comet wrote:

So map script headers have two types of data. Triggers are run once when you enter the map. Callbacks are run more or less once a frame.

Wrong. Triggers are executed with a few cycles in-between each other. You will have an endless loop if you forget to deactivate a trigger at the end of its script. However, your callbacks are only run once upon loading/entering the map!

comet wrote:

An example map script header would look like this: [...]
The trigger is commented out. Maybe it used to do something. It probably contained what is now the callback, but maybe it didn't work properly. I don't know.

It's not commented out or anything. In fact, it runs constantly. Even when the script only contains a ret. Secondly, because your statement implies that it isn't needed: It is needed for a trigger event. Because trigger events and scripts in the primary script header share the same IDs, your game will crash when you have a trigger event on the map but no valid entry in the script header.
Your particular example, IIRC, is the trigger event for the rivals appearance on certain days when he wants to challenge you after you beat the game. However, there is no second trigger entry, because the trigger script is run constantly (it checks a flag) and never deactivated.

comet wrote:

e: presumably the $0000 is an optional parameter.

No, it's just being skipped by all asm code I have ever seen. However, I think there might have been a merit to it in RBGY. The same is true for the 0x0000 in front of the event data. It used to be a pointer for all displayable text per map, IIRC. It's just there because someone did not feel the need to recode all their tools to create two bytes less and run the risk of introducing an elusive and hard-to-find bug in the process :|

cYa,

Tauwasser

Last edited by Tauwasser (2013-02-07 21:13:37)

Offline

Board footer

Powered by FluxBB