• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Need help with inventory

GoliBroda

Member
These are my inventory codes:
Code:
//Create event
empty = "<empty>"
eq[0] = empty
eq[1] = empty
eq[2] = empty
eq[3] = empty
eq[4] = empty
eq[5] = empty
eq[6] = empty
eq[7] = empty
eq[8] = empty
eq[9] = empty
eq[10] = empty
eq[11] = empty
eq[12] = empty
eq[13] = empty
eq[14] = empty
eq[15] = empty
eq[16] = empty
eq[17] = empty
eq[18] = empty
Code:
//First page of the eq menu 
if window = 2 && option <= 9 {
draw_text(xinv,yinv[0],eq[0])
draw_text(xinv,yinv[1],eq[1])
draw_text(xinv,yinv[2],eq[2])
draw_text(xinv,yinv[3],eq[3])
draw_text(xinv,yinv[4],eq[4])
draw_text(xinv,yinv[5],eq[5])
draw_text(xinv,yinv[6],eq[6])
draw_text(xinv,yinv[7],eq[7])
draw_text(xinv,yinv[8],eq[8])
draw_text(xinv,yinv[9],eq[9])
}

//second page
if window = 2 && option > 9 {
draw_text(xinv,yinv[10],eq[10])
draw_text(xinv,yinv[11],eq[11])
draw_text(xinv,yinv[12],eq[12])
draw_text(xinv,yinv[13],eq[13])
draw_text(xinv,yinv[14],eq[14])
draw_text(xinv,yinv[15],eq[15])
draw_text(xinv,yinv[16],eq[16])
draw_text(xinv,yinv[17],eq[17])
draw_text(xinv,yinv[18],eq[18])
}
it works well, draws the empty fields of my eq. But it looks awfull, dont you think that?
and when i start writing the codes for collecting items there will be 2x more of this.

Is there way to optimise these codes to few lines of code?
 

Jakylgamer

Member
you can use for loops to remove a lot of repeated code.
example:
Code:
empty = "<empty>"
for(var i=0; i<max_slots; i++) {
eq[i] = empty;//will set all values to empty
}
and you can do something similar to the draw event but im not sure what the yinv[0] array is for? positioning?
because you can do this for positioning
Code:
for(var i=0; i<max_slots; i++) {
draw_text(xinv,yinv+(i*text_height),eq[i]);
}
 
Last edited:
D

DevNorway

Guest
For initializing, you can backwards initialize it.
Code:
empty = "<empty>"
eq[18] = empty;
 
Top