Difference between revisions of "Sync"

From Unofficial QEdit Wiki Guide
Jump to: navigation, search
(Use)
(Trying to explain it better)
Line 5: Line 5:
  
 
==Use==
 
==Use==
Cause a thread to yield. PSO's quest engine is single threaded and every thread is allowed to on each and every frame. If a thread never yields, the client will freeze. Special menus called through opcodes will yield on their own.
+
'''Sync''' must be used when creating a thread on a looping function. Sync should be called at least once per loop. Not using sync inside of a loop may cause the quest to freeze. One sync equals one frame elapsed in game, and 30 frames equals one second.
  
Pause function for a single frame. Used to delay actions. 30 frames = 1 second
+
On more technical terms, sync will cause the current coroutine to yield, allowing other coroutines to run ([[thread]] actually creates a coroutine and not a thread, and they don't run parallelly). Special menus called through opcodes will yield on their own.
 +
 
 +
Opcodes that will automatically yield:
 +
* [[ret]]
 +
* [[exit]]
 +
* [[window_msg]]
 +
* [[message]]
 +
* [[chat_box]]
 +
* [[disp_msg_qb]]
 +
* [[add_msg]]
 +
* [[list]]
 +
* [[fadein]]
 +
* [[fadeout]]
 +
* [[award_item_name]]
 +
* [[award_item_select]]
 +
* [[award_item_ok]]
 +
* [[get_item_id]]
  
 
==Example==
 
==Example==

Revision as of 05:33, 31 December 2022

Syntax

Syntax: sync

  • None

Use

Sync must be used when creating a thread on a looping function. Sync should be called at least once per loop. Not using sync inside of a loop may cause the quest to freeze. One sync equals one frame elapsed in game, and 30 frames equals one second.

On more technical terms, sync will cause the current coroutine to yield, allowing other coroutines to run (thread actually creates a coroutine and not a thread, and they don't run parallelly). Special menus called through opcodes will yield on their own.

Opcodes that will automatically yield:

Example


100:     call 101 //Call function 101
         window_msg 'Okay. I've waited 1 second. Now what?'
         winend 
         ret 
101:     sync //Pause for 1 frame
         addi R1, 00000001 //Add 1 to register R1
         jmpi_<= R1, 0000001E, 101 //If R1 is less then or equal to 30 jump to 101
         clear R1 //Set R1 to 0
         ret 

Also see

ret, call, window_msg, winend, addi, jmp_<=, clear