Destroying a sequence? Solved

Toque

Member
So I want to press 1 and play a sequence. Then press 2 and play another sequence. This works fine. But the next sequence plays behind the first. So I need to destroy the first. So I have been trying to figure this out with watching videos and manual. But obviously I am missing fundamental understanding of this ( and most things).

create event

sequence = layer_sequence_create ( "top",x,y, seq_1);



Key press 2 {
sequence_destroy (sequence);
}


Obviously this doesn't work.
I love sequences. If someone could point me in the right direction it would be greatly appreciated.
 
Last edited:

Toque

Member
In the sequence editor turn of looping and it will play once only
It only plays once. Yes. It does not loop. But its still drawn and stays visible.

I guess I could just make a new layer and draw the new sequence on a top layer.
But thinking there must be a way to destroy and remove a sequence?

Thanks for your response.
 

Posh Indie

Member
This was tested and works:
Code:
sequence_destroy(layer_sequence_get_sequence(sequence));

This is an educated guess:
In the documentation it's there, just a bit cryptic. layer_sequence_create() does not create the same thing as sequence_create(). In fact, sequence_create()'s result can be fed into layer_sequence_create() (And probably should be) to establish the same link you currently have using an asset sequence in layer_sequence_create(). In either case, where layer_sequence_create() is used, if you want to delete the sequence, you will need to call layer_sequence_get_sequence() on it to get the actual sequence back to feed into sequence_destroy() (you CAN, however, call sequence_destroy() on the result of sequence_create() directly).

Conversely, layer_sequence_*() functions only work on the result of layer_sequence_create() (And not the result of sequence_create() directly without first using layer_sequence_create() on sequence_create()'s result to use with the layer_sequence_*() functions).

Full disclosure:
I have not actually done anything with sequences (Outside of testing the above), yet! The above was gathered solely from the documentation (And just testing the proposed solution to ensure it would work).
 
Last edited:

Toque

Member
This was tested and works:
Code:
sequence_destroy(layer_sequence_get_sequence(sequence));
In the documentation it's there, just a bit cryptic. layer_sequence_create() does not create the same thing as sequence_create(). In fact, sequence_create()'s result can be fed into layer_sequence_create() (And probably should be) to establish the same link you currently have using an asset sequence in layer_sequence_create(). In either case, where layer_sequence_create() is used, if you want to delete the sequence, you will need to call layer_sequence_get_sequence() on it to get the actual sequence back to feed into sequence_destroy() (you CAN, however, call sequence_destroy() on the result of sequence_create() directly).

This is an educated guess:
Conversely, layer_sequence_*() functions should only work on the result of layer_sequence_create() (And not the result of sequence_create() directly without first using layer_sequence_create() on sequence_create()'s result to use with the layer_sequence_*() functions).

Full disclosure:
I have not actually done anything with sequences, yet! The above was gathered solely from the documentation (And testing the proposed solution).
..........................................................................................................
Thanks for you comment and time. Greatly appreciated!!
Hmmm. When I try.......
sequence_destroy(layer_sequence_get_sequence(seqOne));

It errors.

sequence_destroy() - can't delete a sequence created in the IDE at object GML_object_o_controller (line 11).

Okay I understand what the manual and you are saying. If I use instance_sequence_create then I will need its sequence ID to destroy it.

Create the sequence:
seq1ID = layer_sequence_create("seq",320,180,seq_1)

IF button is pressed event:
//get the sequence ID.
hell= layer_sequence_get_sequence(seq1ID)

//Now I can destroy it using the sequence ID.
sequence_destroy (hell);

............................
Of course that doesn't work. It gives the same error. My mind is seq1ID is my sequence ID so why am I getting the ID of a ID?

So I try layer_sequence_get_sequence (seq_1);
Getting the ID directly from the sequence but that gives the same error. But that I kind of understand because its the name of the sequence not the running sequence Id.


And when I create a sequence I am making a "sequence object"? I can't understand what that is.

Seems like a simple thing that is beyond my faculties.
The manual.

With this function you can destroy a sequence object that has been created dynamically. You supply either the sequence object struct (as returned by the function sequence_create()) or the sequence ID (as returned by the function layer_sequence_get_sequence() or from the sequence instance struct property sequence). This function should be used whenever a dynamically created sequence is no longer required to free up the memory associated with it.
 

Posh Indie

Member
I might see the problem. You cannot delete a sequence that was created in the IDE.

GML:
// Step event (Simple test)

// Creation

// Valid
sequence_dynamic = sequence_create();
sequence_1 = layer_sequence_create("Instances", 0, 0, sequence_dynamic);

// Valid, BUT cannot delete the sequence itself later as it was made in the IDE
//sequence_2 = layer_sequence_create("Instances", 0, 0, seq_TestSequenceAsset);


// Destruction

// Valid
sequence_destroy(layer_sequence_get_sequence(sequence_1));
sequence_destroy(sequence_dynamic);
// Possible way to remove the layer_sequence_create() result reference to a sequence created in the IDE?
layer_sequence_destroy(sequence_1);

// Invalid, need to get the sequence itself first
//sequence_destroy(sequence_1);

// Invalid, cannot delete the sequence as it was made as an asset in the IDE
//sequence_destroy(layer_sequence_get_sequence(sequence_2));

// Possible way to remove the layer_sequence_create() result reference to a sequence created in the IDE?
//layer_sequence_destroy(sequence_2); // Maybe? Do not hold me to this one...

If you do try to delete one that was created in the IDE, you will receive the following:

GML:
sequence_destroy() - can't delete a sequence created in the IDE

If you try to delete the result of layer_sequence_create() without first getting the sequence itself, you will receive the following:

GML:
sequence_destroy() - specified sequence not valid
 
Last edited:

Toque

Member
I might see the problem. You cannot delete a sequence that was created in the IDE.

GML:
// Step event (Simple test)

// Creation

// Valid
sequence_dynamic = sequence_create();
sequence_1 = layer_sequence_create("Instances", 0, 0, sequence_dynamic);

// Valid, BUT cannot delete the sequence itself later as it was made in the IDE
//sequence_2 = layer_sequence_create("Instances", 0, 0, seq_TestSequenceAsset);


// Destruction

// Valid
sequence_destroy(layer_sequence_get_sequence(sequence_1));
sequence_destroy(sequence_dynamic);
delete sequence_1; // Maybe? Do not hold me to this one...

// Invalid, need to get the sequence itself first
//sequence_destroy(sequence_1);

// Invalid, cannot delete the sequence as it was made as an asset in the IDE
//sequence_destroy(layer_sequence_get_sequence(sequence_2));

// Possible way to remove the layer_sequence_create() result reference to a sequence created in the IDE?
//delete sequence_2; // Maybe? Do not hold me to this one...

If you do try to delete one that was created in the IDE, you will receive the following:

GML:
sequence_destroy() - can't delete a sequence created in the IDE

If you try to delete the result of layer_sequence_create() without first getting the sequence itself, you will receive the following:

GML:
sequence_destroy() - specified sequence not valid
You are correct I was doing sequences on an asset layer as they did in the youtube tutorial.
If I place it in an instance layer I still get " can't delete a sequence created in the IDE".
The rest of it I will have to try to see later or tomorrow. After a few hours of it I will attack it again later.

I can fudge my way past it. ( just use one sequence per room and keep switching rooms) But I always do this and never really learn anything......

You were very generous with your time. Thank-you
 

Posh Indie

Member
You are correct I was doing sequences on an asset layer as they did in the youtube tutorial.
If I place it in an instance layer I still get " can't delete a sequence created in the IDE".
The rest of it I will have to try to see later or tomorrow. After a few hours of it I will attack it again later.

I can fudge my way past it. ( just use one sequence per room and keep switching rooms) But I always do this and never really learn anything......

You were very generous with your time. Thank-you
Just making sure you saw the warning I added above the code (It's not in the text you quoted): There is memory leaking, even with the error-free destruction in the above.
 

Toque

Member
Just making sure you saw the warning I added above the code (It's not in the text you quoted): There is memory leaking, even with the error-free destruction in the above.

I am an old horse that should be put out to pasture.
You were correct. There are create functions and layer functions and I was mixing them all up. As you explained to me. But not understanding kept chasing that rabbit down the hole.

To destroy a sequence its quite simple.

Create:
sequence = layer_sequence_create("Instances", x,y,seq_1);

To destroy it:
layer_sequence_destroy(sequence);


Tested and works.
Again my thanks for helping me out.
 

Posh Indie

Member
I am an old horse that should be put out to pasture.
You were correct. There are create functions and layer functions and I was mixing them all up. As you explained to me. But not understanding kept chasing that rabbit down the hole.

To destroy a sequence its quite simple.

Create:
sequence = layer_sequence_create("Instances", x,y,seq_1);

To destroy it:
layer_sequence_destroy(sequence);


Tested and works.
Again my thanks for helping me out.
layer_sequence_destroy() will probably solve the memory leak above, too. Not sure why I did not use that instead of delete... In any case, glad you have it figured out!

Edited my response above to remove the memory leak for anyone in the future. I still have them labeled as "maybe" since I cannot actually test for that at this moment.
 

Toque

Member
layer_sequence_destroy() will probably solve the memory leak above, too. Not sure why I did not use that instead of delete... In any case, glad you have it figured out!
Haha yeah.
I kept chasing sequence_destroy. Unaware that layer_sequence_destroy() existed. It was only when I clicked on "layer functions" buried in the manual did I find them. Searching "destroy sequence" in the manual and google will not give layer sequence functions as a result. ......

Thanks again.
 
Top