GMS 2.3+ Array to array but check True False

Quick question.
So I've got an array named The TempBase.

I would like to use a for loop if-else to check the global.TempBase[n,6], only put the True values into the FinalBase array, but I've got no idea how to do it.

This was the structure example what i want to do:


global.TempBase[0,0] = 1;
global.TempBase[0,1] = "Name";
global.TempBase[0,2] = "Desc";
global.TempBase[0,3] = "Use";
global.TempBase[0,4] = "Effect";
global.TempBase[0,5] = "Skills";
global.TempBase[0,6] = false;

global.TempBase[1,0] = 2;
global.TempBase[1,1] = "Something";
global.TempBase[1,2] = "Temp";
global.TempBase[1,3] = "To be Decide";
global.TempBase[1,4] = "To be Decide";
global.TempBase[1,5] = "To be Decide";
global.TempBase[1,6] = true;

global.TempBase[2,0] = 3;
global.TempBase[2,1] = "Hello";
global.TempBase[2,2] = "World";
global.TempBase[2,3] = "I";
global.TempBase[2,4] = "am";
global.TempBase[2,5] = "trying";
global.TempBase[2,6] = true;

after the checker

global.FinalBase[0,0] = 2;
global.FinalBase[0,1] = "Something";
global.FinalBase[0,2] = "Temp";
global.FinalBase[0,3] = "To be Decide";
global.FinalBase[0,4] = "To be Decide";
global.FinalBase[0,5] = "To be Decide";
global.FinalBase[0,6] = true;

global.FinalBase[1,0] = 3;
global.FinalBase[1,1] = "Hello";
global.FinalBase[1,2] = "World";
global.FinalBase[1,3] = "I";
global.FinalBase[1,4] = "am";
global.FinalBase[1,5] = "trying";
global.FinalBase[1,6] = true;


Hope you understood.
In advance-thank you.
 
Last edited:

trip

Member
Question is. Do you want to create a new array in Final base or conneted array with temp ?

you can try this:
GML:
for (var _i=0 ; _i < array_lenght(global.TempBase) ; _i++){
    if global.TempBase[_i][6]{
        array_push(global.FinalBase,global.TempBase[_i])
    }
}
 
Question is. Do you want to create a new array in Final base or conneted array with temp ?

you can try this:
GML:
for (var _i=0 ; _i < array_lenght(global.TempBase) ; _i++){
    if global.TempBase[_i][6]{
        array_push(global.FinalBase,global.TempBase[_i])
    }
}
I may want to create a new array.
Temp Array to Final Array, if "TempBase[n,6]" are false, then just don't put those values in the Final Array.
 

trip

Member
May be is a shorter solution then my solution.
For create new array:
GML:
for (var _i=0 ; _i < array_lenght(global.TempBase) ; _i++){
    if global.TempBase[_i][6]{
        var _array = array_create(array_lenght(global.TempBase[_i]))
        for (var _j=0 ; _j < array_lenght(_array) ; _j++){
            _array[_j] = global.TempBase[_i][_j]
        }
        array_push(global.FinalBase,_array) // global.FinalBase must be defined like array anywhere before
    }
}
 
May be is a shorter solution then my solution.
For create new array:
GML:
for (var _i=0 ; _i < array_lenght(global.TempBase) ; _i++){
    if global.TempBase[_i][6]{
        var _array = array_create(array_lenght(global.TempBase[_i]))
        for (var _j=0 ; _j < array_lenght(_array) ; _j++){
            _array[_j] = global.TempBase[_i][_j]
        }
        array_push(global.FinalBase,_array) // global.FinalBase must be defined like array anywhere before
    }
}
wow, it works, thank you very much.
You are my hero!
 

Nidoking

Member
This looks like another case for adding structure to your "second dimension" and just using structs to store the meaningful data. Then you'd have a one-dimensional array of structs, which is easier to manage.
 
Top