Thanks!
Edited by vinicius, 22 September 2012 - 10:26 PM.
Posted 22 September 2012 - 02:14 PM
Edited by vinicius, 22 September 2012 - 10:26 PM.
Posted 22 September 2012 - 03:29 PM
clone = ds_stack_create(); //Create an auxiliar stack ds_stack_copy(clone, your_original_stack); //Copy your source data in this auxiliar stack
while(ds_stack_size(clone) > 1){
ds_stack_pop(clone); //Bring out unnecessary elements until there is only one and...
}bottom_value = ds_stack_top(clone); //Last remaining element in the clone stack is the bottom value. ds_stack_destroy(clone); //Get rid of the clone, you won't need it anymore.
var source;
source = argument0;
clone = ds_stack_create(); //Create an auxiliar stack
ds_stack_copy(clone, source); //Copy your source data in this auxiliar stack
while(ds_stack_size(clone) > 1){
ds_stack_pop(clone); //Bring out unnecessary elements until there is only one and...
}
bottom_value = ds_stack_top(clone); //Last remaining element in the clone stack is the bottom value.
ds_stack_destroy(clone); //Get rid of the clone, you won't need it anymore.
return bottom_value;Edited by Tennx, 22 September 2012 - 03:36 PM.
Posted 22 September 2012 - 09:28 PM
Not worked, this script do the same as ds_stack_top(). .... And I know Stacks are FILO, so I´m using them. What I´m asking is why we do not have a function to see the last stack push? I know that I can use a variable like last_entry or something like that but why we do not have a function to deal with it? Or we have and I was not be able to find?Why do you use stacks? Stacks are meant to be FILO (First In Last Out), so there must not exist a function that reveals the first element until it is the last on stack.
You should use ds_list instead so you can make reference to the position directly, and the code runs faster.
Well, if you want to get the bottom element, you can copy your stack withclone = ds_stack_create(); //Create an auxiliar stack ds_stack_copy(clone, your_original_stack); //Copy your source data in this auxiliar stack
And then...while(ds_stack_size(clone) > 1){ ds_stack_pop(clone); //Bring out unnecessary elements until there is only one and... }
Finally...bottom_value = ds_stack_top(clone); //Last remaining element in the clone stack is the bottom value. ds_stack_destroy(clone); //Get rid of the clone, you won't need it anymore.
In resume...
ds_stack_bottom(id):var source; source = argument0; clone = ds_stack_create(); //Create an auxiliar stack ds_stack_copy(clone, source); //Copy your source data in this auxiliar stack while(ds_stack_size(clone) > 1){ ds_stack_pop(clone); //Bring out unnecessary elements until there is only one and... } bottom_value = ds_stack_top(clone); //Last remaining element in the clone stack is the bottom value. ds_stack_destroy(clone); //Get rid of the clone, you won't need it anymore. return bottom_value;
Use that script, tell me if it works.
---
Oh, and by the way... next time you need some advice about functions, GML or code, go in here: http://gmc.yoyogames...php?showforum=2
Posted 22 September 2012 - 09:48 PM
You're mixing up stacks with queues. The last value pushed onto the stack is the value returned by ds_stack_top(). If you need access to both ends, you have to use a list as Tennx suggested.We have ds_stack_top() to get the first stack value. So what I want is how to get the last value pushed onto the stack?
Posted 22 September 2012 - 10:25 PM
Hmmm, I misunderstood when reading the manual. So, thanks you guys on help me.You're mixing up stacks with queues. The last value pushed onto the stack is the value returned by ds_stack_top(). If you need access to both ends, you have to use a list as Tennx suggested.
We have ds_stack_top() to get the first stack value. So what I want is how to get the last value pushed onto the stack?
GameGeisha
0 members, 0 guests, 0 anonymous users