• 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!

GML How do I fix this code

O

OriginalGrim

Guest
Untitled.png
I'm trying to make an inventory but I realized that when I put in a certain combination of inputs it completely throws off the math and results in option = things outside of 0-5 is there an easy way to fix this?

object = 0
maxobject = 4

step:
if keyboard_check_pressed(ord("S"))
option += 1;
else if keyboard_check_pressed(ord("W"))
option -= 1;
else if keyboard_check_pressed(ord("D"))
option += 2;
else if keyboard_check_pressed(ord("A"))
option -= 2;


if option < 0
option = maxoption;
else if option > maxoption
option = 0;


}

if keyboard_check_pressed(vk_enter)
{
switch option
{
//invetory
case 0:
break;
//equipment
case 1:
break;
//status
case 2:
break;
//synopsis
case 3:
break;
//save/load
case 4:
if instop = false {
instance_create_layer(view_xport[0] + 640, view_yport[0] + 73, "SLQ", obj_SLQ)
instop = true;
}
break;
//settings
case 5:
break;
}
}
 

obscene

Member
You probably want to add or subtract 6 instead of set it to 0 or max.

But my earlier question was... are you confusing two variables maxoption and maxobject?
 
O

OriginalGrim

Guest
You probably want to add or subtract 6 instead of set it to 0 or max.

But my earlier question was... are you confusing two variables maxoption and maxobject?
yeah max object should say max option I don't know how that got like that it's proper in gamemaker.
 
D

DekuNut

Guest
We could fix this code, but wouldn't it be easier to use an array?

create:
Code:
inv = -1;   //INITIALIZE INVENTORY ARRAY
h = 0;      //HORIZONTAL OPTION
v = 0;      //VERTICAL OPTION
max_h = 3   //MAX # OF INVENTORY SLOTS IN A ROW
max_v = 1   //MAX # OF INVENTORY SLOTS IN A COLUMN

option = -1;//INITIALIZE OPTION ARRAY

step:
Code:
if keyboard_check_pressed(ord("S")) v += 1;
if keyboard_check_pressed(ord("W")) v -= 1;
if keyboard_check_pressed(ord("D")) h += 1;
if keyboard_check_pressed(ord("A")) h -= 1;

if (h < 0) h = max_h;
if (v < 0) v = max_v;

if (h > max_h) h = 0;
if (v > max_v) v = 0;

if keyboard_check_pressed(vk_enter) {
    switch inv[h, v] {
        case inv[0, 0]:
            break;
        case inv[0,1]:
            break;
        case inv[1,0]:
            break;
        case inv[1,1]:
            break;
    }
}

upload_2018-12-13_19-0-16.png
 
Top