Chapter 2. Drop the Chess Down
~~~~~~~~~~~~~~~~~~~~~~~~~~~
In this chapter we will use Rexrainbow's <Gridmove> plugin to drop chess down. If you had never tried to moved a chess by <Gridmove> plugin, please go back and finish tutorial#1 before you move on.
First, add <Gridmove> behavior to [chess] object. And keep all the default settings:
Second, add the following code to your event sheet:
In Event#6, we add a 0.6 seconds wait before we call "dropdown" to drop down the chess. This is because it will take 0.5 seconds to flash the chess, and we introduce an extra 0.1 seconds as a safty gap.
Event14 ~16 is the "dropdown" function. Please be cautious with the indents. In Event15 we let <Board> to sweep each grid from bottom to top (Why? Try turning this option to <top to bottom> and answer the question by yourself). And in Event16 we introduce an while loop forcing picked chess to drop down to bottom.
Push <F4> to run layout, something weird happens: It looks like that <Board> removes some chess while other chess are still dropping. This is because Event#6 is executed every 1.0 seconds, even when some chess are not stabilized. This problem sounds hard to solve because we don't know how long should be we wait for the dropping process since every dropping chess has different distance to drop. Fortunately, you got Rexrainbow's plugin right? Let's solve this difficult problem by Rexrainbow's <Wait Event> plugin.
OK, now here comes the hardest part of this tutorial. Turn to <Layout 1> and add <Wait Event> plugin to your project.
Edit <Event Sheet 1> as follows:
Look at Event3 and 7 first. In the previous design we call Event7 every 1.0 seconds and cause the problem, so this time we turn Event7 to be a function named "loop" and just call it once in Event3. So next time if we want <Board> to do the process again (match, remove, and drop down), all we have to do is to call "loop" function again.
Next, in Event#17 we use <WaitEvent> plugin to register a waitevent with its name set to the dropping chess' UID . The concept for this waitevent will be: If this waitevent is alive, then it represents the corresponding chess is dropping right now; Otherwise if this waitevent is finished, then it represents the corresponding chess has finished dropping. We give it a tag "dropdown" so later we can detect waitevent status by this tag.
Event#18 will be triggered if some [chess] finished dropping. In this case, we have to finish its corresponding waitevent.
Event#19 detect wheter all waitevents with "dropdown" tag have been finished. If yes, call the "loop" function again.
Push <F4> to run layout, now you can see <Board> does everything in the right timing.