Jump to content

Photo

Detect inherent flag of a moving block


  • Please log in to reply
4 replies to this topic

#1 idontknow8

idontknow8

    Senior

  • Members

Posted 19 January 2021 - 11:05 PM

I thought this would be the script for detecting if a moving combo - aka a push block in motion - has an inherent flag:

 

Screen->ComboI[ComboAt(Screen->MovingBlockX, Screen->MovingBlockY)]

 

It's part of a larger FFC script that checks all combos for a certain inherent flag and if so, it sets a bool statement to true...it keeps looping every frame as long as the FFC exists - a while(true) loop to constantly check.

 

 
ffc script Secrets_if_No_Combo_Flag_Appears{
void run(int combo_flag, int sound_fx){
bool combo_found = true;
int j = 0;
while(true){
j = 0;
while(j<176){
 
if(Screen->ComboI[j] == combo_flag){
combo_found = true;}
j++;
}
while(Screen->MovingBlockX > -1 || Screen->MovingBlockY > - 1){
Waitframe();
}
if(combo_found == false){
Screen->State[ST_SECRET] = true;
Screen->TriggerSecrets();
Game->PlaySound(sound_fx);
Quit();
}
Waitframe();
combo_found = false;
}
}

 

}

 

The idea is that once there no longer exists any combos with said inherent flag, secrets trigger.  The problem is that I want this to apply to push blocks but the second the block gets pushed, secrets get triggered because a moving block doesn't count as one of the 176 combos on screen.  While the script does compile just fine, when I go to test it, I change all combos except for one push block and when I push that block, it causes triggers to change but I want it to wait until that block is pushed on a trigger. 

 



#2 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 19 January 2021 - 11:15 PM

Assuming this is 2.53 or 2.50, there's no way to get that information directly. You could keep track of each flag on the screen and see which one changes when the block starts moving, though that's a bit of a hassle. I think something like this ought to work:

int temp=Screen->ComboD[0];
Screen->ComboD[0]=Screen->MovingBlockCombo;
int flag=Screen->ComboI[0];
Screen->ComboD[0]=temp;


#3 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 20 January 2021 - 02:03 AM

Move the `while(Screen->MovingBlockX > -1 || Screen->MovingBlockY > -1)` *above* the `j = 0' at the top.



#4 idontknow8

idontknow8

    Senior

  • Members

Posted 20 January 2021 - 02:56 AM

Trial and error - had to move it inside the 'while (j<176) loop.  I struggle with loops & order of operations sometimes - a lot actually.  A lot of my 'scripting' is trial and error with loops.  Anyone else feel same way?



#5 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 20 January 2021 - 01:02 PM

Oh, I should read the whole post, huh. :P
 
When you're doing something to each of something, like each combo on the screen, it generally makes more sense to use a for loop.
for(int j=0; j<176; j++) {
    if(Screen->ComboI[j] == combo_flag) {
        combo_found = true;
        break; // No need to keep searching
    }
}
Functionally, it doesn't make any difference. But ZScript is a language, and the way you use language should reflect your thinking. Reading and writing code are both easier when you know the appropriate idoms - but, of course, it takes some work to learn them.

I don't know if it's helpful at all, but I wrote this post trying to explain how to translate from concept to code. And this thread could use more activity.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users