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

Help with code to make foods rot

J

jacobj30

Guest
So i am creating a cooking game, and i thought the the game would be better if the food rotted if it is not stored in a freezer. So i thought about how the code would work. and i came up with the below. There is no problem with the code below but i want it more streamlined. i do not want to have to create almost a thought didn't variable for each food. Because if you buy 1 meat then global.meat_1_bought=true would be active, but if you buy another meat nothing would happen because global.meat_1_bought=true is already active. which would mean having to create meat 1,2,3,4,.... & etc. i do not want to do that because it would take too much time so if anyone could show me a way to streamline it then i would be really happy. but if there isn't then i would instead continue what i have been doing.

Note that code below could have some mistakes but i do not want you to focus on the mistakes but instead an alternative to this. that is much faster. So please do not point out the mistakes. i could figure out the mistakes by opening the game up.

VARIABLES:
global.subtract=1; /// this will be used later
global.meat_expiration=irandom_range(4,6); /// # of days meat 1 can be out without spoiling.
global.meat_1_expiration=0; /// # of days ( meat 1) can be out without spoiling
global.meat_1_in_freezer=false; ///the food is in the freezer
global.meat_1_bought=false; ///you have bought your meat

buying the meat left click
randomize();
global.sub=1; /// i use the variable sub as a way to stop the code.
if ( meat_1_in_freezer=false && global.meat_1_bought=false && global.sub=1 ) {
global.meat_expiration=irandom_range(4,6); /// # of days meat 1 can be out without spoiling.
global.meat_1_expiration+=global.meat_expiration;
global.meat_1_bought=true;
global.meat_1_in_freezer=true;
global.sub-=1 }

step event
if ( global.meat_1_expiration==0 ) {
global.meat_1_bought=false;
global.meat_1_in_freezer=false; }

so now lets say i click next day and this is what is suppose to happen.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
if ( meat_1_in_freezer=true && global.meat_1_bought=true) {
global.meat_1_expiration-=0; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////
if ( meat_1_in_freezer=false && global.meat_1_bought=true) {
global.meat_1_expiration-=1; }

what i want is to buy as many meats as possible without having to create a thousand variables. so is there a code or codes that can allow me to such a thing. i hope you understand what i mean
 
Last edited by a moderator:

Bingdom

Googledom
I would recommend putting this into code blocks, it makes it much easier to read. ;) After that, ill see what i can do.

Edit:
I would recommend taking a look at ds_lists()
 
Last edited:
J

jacobj30

Guest
I would recommend putting this into code blocks, it makes it much easier to read. ;) After that, ill see what i can do.

Edit:
I would recommend taking a look at ds_lists()
the code doesn't really matter it is just there to make you better understand what i am saying.
 

Bingdom

Googledom
the code doesn't really matter it is just there to make you better understand what i am saying.
Hmm, ok. After thinking about it for a while, it probably be best to store the information into a ds_grid.

So what you can do is get the total amount of meat by using ds_grid_width. Durability can be stored on the x-axis and frozen state can be stored 1 below it. Hopefully this makes sense. Then you can make a loop that will check if that section is frozen, if not then remove durability by 1.
 
Top