Difference between revisions of "Common functions"

From Unofficial QEdit Wiki Guide
Jump to: navigation, search
(Count Up Timer)
(Custom Functions)
Line 96: Line 96:
 
The labels and non-reserved registers here are purely for example.
 
The labels and non-reserved registers here are purely for example.
 
When using the code in the following functions, please adjust for your needs.
 
When using the code in the following functions, please adjust for your needs.
 +
 +
Notice that again, you will need to remove comments (text after and including #'s) when putting this into QEdit.
 
===Count Up Timer===
 
===Count Up Timer===
 
Credit: Lemon
 
Credit: Lemon

Revision as of 20:12, 8 May 2019

This page holds many functions that should serve as a helpful reference. Some functions hold specific numbers because they are so broadly used and treated as if they are reserved they will be labeled as "Function #: Name". It's a best to write any custom functions with a label of 152+. Common function examples that do not have a specific number tied to them will be labeled as "Custom Function #: Name" and placed after the regular functions.

Keep in mind that these snipets are meant to be guides, and show some level of standard, but may not always be suitable for direct reuse.

As you learn to use QEdit you will find that any of these may need changes, additions, or that some functions will have strange quirks.

Please update any function with the appropriate notes for the betterment of the community, and please keep these in numerical order.

You'll also notice some commonly used registers used here. For more information see common_registers

Function Intro

It is highly recommended that you take the time to understand the following before using this page

  • How setting registers works
  • How calling vs. jumping works
  • What the reserved registers are

Pseudo-reserved Functions

With the exception of 0, none of these needs to use the number listed, but it is a good standard and lets people read and write code more quickly.

Function 0: Main

NOTE: This is the only reserved function, and always runs when a quest is loaded. This is your "main".

The following code is the bare minimum 0 required to start a quest.

This only sets the variables needed to load into pioneer2 in this example, then calls 150 to set the quest to started.

Whatever you do, just be sure that in your chain of functions that 0 sets off, that R0 gets set (done here in 150 -> 151).

V2:

V1:

GC:

0:      set_episode 00000000
        set_floor_handler 00000000, 150
        leti R60, 00000000
        leti R61, 00000000
        leti R62, 00000000
        leti R63, 00000000
        leti R64, 00000000
        map_designate_ex R60
        ret

BB:

Function 1: Ret

This function is commonly used to be a "do nothing" sort of script. You'll see frequently that this is used in scripts to quickly terminate switches

1:      ret

Function 2: Start Cinematic

This function essentially disables the character, hides hud, and zooms in with cinematic bars

2:      p_action_disable 
        npc_nont
        disable_movement2 R250
        hud_hide 
        cine_enable 
        cam_zmin 
        ret

Function 3: End Cinematic

This undoes the changes that 2 does, but in reverse order. This should help avoid errors, and let the player play again.

3:      cam_zmout 
        cine_disable 
        hud_show 
        enable_movement2 R250
        npc_talk
        p_action_enable 
        ret

Function 150-151: First Map

Here we see a common use of function 1.

If we follow the example from function 0, you will note this is called every time you load into Pioneer 2, so we only jump to 151 if the quest is not yet started, otherwise do nothing by jumping to 1.

Technically speaking the only thing required here is to set R0, but to be slightly more illustrative I've put here to play the jingle in here.

Often what is added here is teleporting the player, a call to 2, Quest Giver NPC Intro speech, a call to 3, then setting R0 (sometimes this is done before talking, or during talking), then the music.

150:    switch_jmp R0, 2:151:1
151:    set R0
        bgm 00000001
        ret

Custom Functions

The labels and non-reserved registers here are purely for example. When using the code in the following functions, please adjust for your needs.

Notice that again, you will need to remove comments (text after and including #'s) when putting this into QEdit.

Count Up Timer

Credit: Lemon In use this set of functions

# Registers
# R1 = start time
# R2 = current time \ display time

# Timer Start
1:      gettime R1              # store start time for reference
        sync_register R1, R1    # sync the register so all clients share the same start time
        window_time             # display the timer
        jmp 2

# Timer Loop
2:      gettime R2                  # get current time
        sub R2, R1                  # calculate the elapsed time
        winset_time R2              # display elapsed time
        call 3                      # wait 30 frames (~1 second)
        jmp_on 1, 1:255             # exit if we win
        jmp_on 1, 1:235             # exit if we lose
        jmp 2                       # otherwise loop

# Wait 1 second
3:      call 4
        call 4
        call 4
        call 4
        call 4
        ret

# Wait 1/5 second
4:      sync
        sync
        sync
        sync
        sync
        sync
        ret