SOLVED Making a good powerup combining system

Mush

Member
I'm making a shoot em' up game which you can collect three types of powers and then mix them between two slots to make different types of bullets you can shoot, and, while i managed to make a working system for it, i think the powerup combining part is kind of obtuse and outdated. It may be simple, but is akwardly long. To get an idea, here's how long ONE section of it looks:
GML:
if can_shoot = true
{
    if slot1 = 0
    {
        if slot2 = 0
        {
            if instance_number(bullet0) < (number)
            {
                //Code for normal bullet
            }
        if slot2 = 1
        {   
            if instance_number(bullet1) < (number)
            {
                //Code for fire+normal bullet
            }
        }
        if slot2 = 2
        {   
            if instance_number(bullet2) < (number)
            {
                //Code for multi+normal bullet
            }
        }
        if slot2 = 3
        {   
            if instance_number(bullet3) < (number)
            {
                //Code for homing+normal bullet
            }
        }
    }
}
I don't mind having to write all those lines of code, but i wanted to know, is there any better (and shorter) way to write this?
 

Nidoking

Member
You might consider packaging some of that into scripts/functions and storing those in a two-dimensional array or grid. You'd then call the script in [slot1, slot2].
 

TheouAegis

Member
You could do it all numerically.

You could have a 2-index array to hold each item. Then condense the array down to 1 variable like:
equips = slot[0] + slot[1] * 4;


You could do it without the array, just have a variable keep track of which slot is currently being added to.
equips = (equips & ~( 3 << slot * 2) ) | (item << slot * 2);
 

Mush

Member
Sorry for responding kind of late, but can you tell me how to do an array? I'm using GameMaker 8.1 Lite.
 

TheouAegis

Member
Do you know how to use alarms or views? Alarms and views are arrays.

alarm[0]
alarm[1]
alarm[2]
alarm[3]

The variable is alarm. By putting a number inside brackets right after it, it becomes an array, which is just a series of variables organized together.
 

Mush

Member
Well, i'm still starting to learn about the basics of arrays, but thanks a lot for the help you gave me! The GM doc i'm reading says that they are pretty useful for many stuff, so it will be pretty sweet if i learn how to use this, so, once again, thanks! :)
 
Top