[SOLVED] frame in loop triggers event.

Started by Nixxon, Mon 19/10/2015 03:09:23

Previous topic - Next topic

Nixxon

Hi All,

I've done a fairly extensive search but not sure if this is at all possible.

I have two objects in a room. Is there away to have object 1 become invisible (Via object[1].Visible = False) when object 2 reaches a certain frame in its View/Loop?

Many thanks in advance,

Gilbert

Yes. Put something like this in repeatedly execute always:
Code: ags

if (object[2].Frame == 4) object[1].Visible = False;


Nixxon

#2
Thank you so much, cannot wait to try this.

EDIT, just tried this and it didn't work :( Any ideas?

Do i have to specify the View? To clarify, the script runs and compiles but the object doesn't disappear.

Vincent

I think it depend how you handled to cycle the frames in a loop, probably there's a mistake somewhere else..

Crimson Wizard

#4
Quote from: Nixxon on Mon 19/10/2015 03:21:40
Do i have to specify the View?
You need to set up a proper condition, depending on how precise you want it to be.
Do you want the action trigger whenever object 2 is at the frame 4 of any loop and view? Then specify only Frame.
Do you want the action trigger only if object 2 is at the frame 4 of certain loop but any view? then specify both Loop and Frame.
If you want this happen only if object 2 is at frame 4 of particular loop and view, then specify View, Loop and Frame.

Vincent

I believe you will need to see these sections into the manual

// Game.GetViewFrame
// Returns a ViewFrame instance for the specified frame in the specified loop of the specified view.
// This instance allows you to query properties of the frame itself, such as its graphic, its frame -linked sound setting, and so forth.
Code: ags

// example
ViewFrame *frame = Game.GetViewFrame(SWIMMING, 2, 3);
Display("Frame 3 in loop 2 of view SWIMMING has sprite slot %d.", frame.Graphic);



// Game.GetLoopCountForView
// Returns the number of loops in the specified view
Code: ags

// example
int loops = Game.GetLoopCountForView(SWIMMING);
Display("The SWIMMING view (view %d) has %d loops.", SWIMMING, loops);



// Game.GetFrameCountForLoop
// Returns the number of frames in the specified loop of the specified view.
Code: ags

// example
int frameCount = Game.GetFrameCountForLoop(SWIMMNG, 2);
Display("Loop 2 in SWIMMING view has %d frames.", frameCount);

MiteWiseacreLives!

#6
Quote from: Gilbert on Mon 19/10/2015 03:18:45
Yes. Put something like this in repeatedly execute always:
Code: ags

if (object[2].Frame == 4) object[1].Visible = False;

Perhaps what you forgot to tell us is that this occurs along with a looping animation? In that case you need to also put this into Repeatedly execute always:
Code: ags

else if (object[2].Frame == 5) object[1].Visible = True;


E: looking above maybe this isn't the problem.. Without any more details on the views and loops and your running and where in the script your placing this, I can only suggest make a loop for object[2] that ends at frame four. Run that loop with eBlock then object[1].Visible=false then call the next loop of animation on object[2] that will finish off   

Snarky

If I'm not remembering entirely incorrectly, frames are numbered from 0, so keep that in mind when figuring out which frame to test for.

Basically, this should work, so if it doesn't there must be a mistake somewhere. If you post your code we might be able to spot it.

Nixxon

Hey guys,

I've had little luck thus far. Please find the room code below -

Code: ags
// room script file

function room_AfterFadeIn()
{
object[1].Move(330, 250, -4, eNoBlock);  
cPedoMan.Say("&7 Aaaaarrggghh!!!! In the name of Billy Mac and his five brothers!");
Wait(25);
object[0].Visible = true;
object[0].SetView(6);
object[0].Animate(0, 2, eOnce, eNoBlock);
Wait(70);
object[0].Visible = false;
Wait(40);
player.ChangeRoom(3,  266, 241);
}

function room_RepExec()
{
if (object[0].Frame == 5) object[1].Visible = false;
}


Some images of the room, and the loop below if that helps?







Really appreciate this fellas. Bugging me for a few days.

Crimson Wizard

#9
Room_RepExec is not run during Wait() (nor during other blocking actions). You must use repeatedly_execute_always, as Gilbert pointed out in the first reply (perhaps, it was not made clear that it is a name of function).

Like:
Code: ags

function repeatedly_execute_always()
{
if (object[0].Frame == 5) object[1].Visible = false;
}

Nixxon

Amazing, works beautifully now. Sorry I missed that initial comment. Got a little overwhelmed.

Thanks heaps guys, fkn really appreciate it.

SMF spam blocked by CleanTalk