Hey guys -- I made a mistake in the video by forgetting to alter the "growing" code when we ENTER the room. As it stands, since we just copy-pasted the code from the pressing "G" event, entering a room will also increment the number of daysOld. Which makes no sense! We'll fix this in the next-next video (I've already recorded the next one unfortunately), but for now, if you want to fix it, change the code to this: pastebin.com/PjM8smwZ
I love carrying on with this series after watching the view counts/like counts drop over the last 4 videos. It makes me feel like we're the few the proud who are still going cus we really wanna learn everything we can ha
So happy to see this video pop up today! It's really been a joy following the series so far. Eagerly awaiting the next one! Edit: I noticed that if I was in planting mode and transitioned rooms while crops were currently growing, my game would crash. Omitting the "ds_grid_destroy(ds_crops_instances);" at 8:42 seems to have fixed it although I'm not savvy enough to know if it will cause any issues down the road. Super minor but I thought I'd share in case anyone experienced the same thing. Cheers!
I had the same issue. I tried adding "if planting planting = !planting" just above "ds_grid_destroy(ds_crops_instances);" in the Room End event. Seems to work.
A little fix that maybe is adressed later, but i've encountered here and maybe someone else could find it here too and find this helpfull. When you leave the room on planting mode the game crashes because the draw event on the crop object doesnt find a ds_crops_instances grid. We delete it on room end and only recreate it if we are on rm_farm. I fixed it by adding: if(room != rm_farm) exit; on the beggining of the draw event on the crop object. But now if you click on the other room you crash the game too, so i've added: and room = rm_farm on the condition to plant on the step event, so planting is only alowed in the farm room. Sorry if my english is not so good. Thanks for the videos! ;)
I've encountered your solution now on P12, add if(room != rm_farm) {planting = false; exit;} on the step event of the crops object. Simpler and better than my solution, so i leave it here.
Hello - you're doing a good job with your tutorials. On persistence, you could also set the room to be persistent to retain the non-persistent instances created in that room.
Firstly, let me say what a brilliant set of tutorials these are! Well done! Looking forward to seeing how they develop. But I think I found a couple small things, maybe one small glitch. Which occurs about here in the tutorials, once we implement the growing system. Once the grids are in place, once you press P for planting mode, if you drag the mouse down to the bottom of the camera and viewport (noting that for me this occurs at the bottom of the room), I seem to draw a red box (ie no soil here to plant in) mostly off screen which provides the following output in the console: Grid 3, index out of bounds writing [1,28] - size is [47,28] The 1 in [1,28] will change depending on which column the mouse is in, 1 is to the first left, which will increment up by 1 each cell to the right I move... The second thing is more of a “glitch” perhaps. I’m pretty sure my code is right up to this point. But, if you again press P for plant mode, and drag slowly to the left most side of the viewport such that the box / selected crop is up against the edge of the room / viewport - while initially a red box, returning the debug message of no soil - if you slowly drag the mouse off the edge of the viewport, there is a small window you have presented to you where the box turns green (and to be clear this box is fully in the viewport and camera, it doesn’t offer any option to construct that box out of view, as per the issue above) and while the cursor is ever so slightly off the viewport you can press on that green box and plant a crop where there is no soil to do so. This is remembered and recalled accurately if you change rooms and come back. I tested this on the right most side of the room, and find the same Grid console message as above, this time changing the second digit in the square brackets not the first (as was the case when you pull the mouse off the bottom of the viewport). I’ve been playing with it for 15 mins and I think it’s some combination of the cell and data variables in the instance_create_crop script which is called once the mb_left is pressed. Or, I’ve got a feeling that perhaps it’s related to the size of the room, viewport and camera all needing to be in increments of 32 (cellSize)... any thoughts would be appreciated - and apologies if this has already been picked up or sorted in later tutorials. You rock, cheers
Apologies for the late reply, I was away on a trip! Ah this will be to do with the fact that we made the grid to "fit" the room size. Since the "origin" of the x and y axis is at (0,0), and then stretch down and to the right, those "out of bounds" errors appear at the bottom and right boundaries. As for the "glitch" - ah I can reproduce this in my project too. We will definitely need to return and fix these issues in later tutorials, so thank you for letting me know!! I'll include a fix more formally in the tutorial, but for now, this seems to fix the issue: Exactly as you say, the problem is in the instance_create_crop script, and is actually a quirk of how the tilemap function works. We were checking if there was soil absent by seeing if the "data" from the tilemap_get_at_pixel (at the point we click) is equal to 0. But the problem is, if there is NO tile at ALL (like for positions outside the room), it's actually = -1. But, since -1 != 0, it was allowed to pass as if soil was present. So we could change this to instead check if(data
Awesome work again! Please don't stop repeating bits of what we have learned in the previous parts, the quick references are a great refresher (like you seem to do so far) ;) Especially with array stuff, let alone with multiple grids that work together, it can get very abstract fast if you need to process a lot of new information on top of that. So, again, I really appreciate the images - I would be lost if I had to keep that in my mind while following along (and would not actually learn anything but just blindly copy your code without understanding it). And if I may make a suggestion (after saying that I really like the pace of your videos and their requirement of my commitment); Sometimes you skip/speed up tedious bits, but I feel they go a bit unnoticed and so I miss out on valuable info. I do not constantly look at the video, because I try to predict what the next piece of code will be or whatever. So maybe you could describe a bit more what is happening on screen. Like "So if we look at the excel sheet again.." so i know i have to look up instead of getting to know what i typed. Or when you speed up copy/paste code maybe a bit more pause in between or a short comment to indicate what you currently are pasting if you skip over it. It is a lot of new info (like this comment hehe) so yeah please keep repeating/refering until we are sick of it. Then we know for sure! I'm sure I won't need the extra nudges when I'm more advanced. But it would be nice to stay in a flow without searching for something that I've missed out on. Sorry for the ultra long comment, I just want to clearly state that it's a minor thing again and that your work and effort is amazing. Thank you. :)
Thanks so much Robin! I'm glad you haven't found the repetitions tedious, I'm trying to strike a balance but I know it's almost pointless since some viewers might not have watched previous episodes, some are at different experience levels, etc. Perhaps erring on the side of "too much explaining is better than too little" is best! Ah, that's a great suggestion!! Unfortunately I've already recorded the next video, but I'll try to do this next time. I hadn't really thought about it, but I definitely remember having the same troubles when watching other people's tutorials: looking at my project and missing something on the screen. Always lovely to hear from you - you're very kind, and I really appreciate the feedback/suggestions :)
FriendlyCosmonaut Yeah I can understand that it's hard to judge the pacing as when you are a more advanced and experienced. But it's easier to pickup on things when you are aware of it's usage. And this for me personally is learning a totally new foreign language. And I am used to doing programming is a different way. So yeah, I would much rather feel that I already know it, than forget what I have learned. And the people who have not watched enough to get your short references should not be surprised. This is part 10 of a series, if they need a refresher I'm sure they can get what they need from it or should be willing to search it out. But the intention is to build a farm together from the ground up, at least that's what I assume. (And hey maybe you will get even more views this way as an added bonus ;p ) But I'm happy to hear that my feedback is well received! Keep it up :)
If you get a divide by 0 error when reentering the farm, make sure you didn't make a mistake with the respawn_crop function. I spent half an hour troubleshooting only to realize I put "crops.ds_crops_instances" instead of "crops.ds_crops_types"...
I have one issue: when I press p in the house it crashes. I fixed that by only allowing to go into plant mode while in rm_farm. But when i enter the house while planting is active it crashes too because ds_crops_instances doesnt exist. I am pretty new so idk how to fix this. Any ideas? EDIT: I fixed it by putting if(room != rm_farm){ planting = false;} on top of the planting code.
Could someone please help? I get this error when I change rooms: Data structure with index does not exist. at gml_Object_crops_Draw_0 (line 9) - var cell = ds_crops_instances[# gx, gy]; It was working fine at the end of the previous video but suddenly after adding the code to make the crops persistent that line broke.
I got this too. The thing that's causing it for me is if I have the "Plant Crop" button enabled. If you see the crops on your mouse cursor, press P to remove it and then try zoning and coming back. Other than this strange problem, it's working. Another person said they got the same problem and that it'll be fixed soon. Perhaps its fixed in one of the later vids for this series.
Hi! I have a silly question 😅 Why do we have to destroy a data structure when the game ends? Doesn't it automatically get destroyed when the game ends?
So strange! I've triple-checked ALL code but still, when I plant stuff, then go to leave rm_farm to check persistence, I get an error about: "Data structure with index does not exist. at gml_Object_crops_Draw_0 (line 11) - var cell = ds_crops_instances[# gx, gy]; " So I think I must have made a typo in code or something, but I can't find it! I'll try tomorrow
I've had the same error too. In the crops object in the room end event add the following lines: if (planting){ planting = false; } So it turns off planting mod before leaving room I don't know if it will be fixed in the next videos, but this is a quick solution I've found
Like your way of saving persistent data between rooms. While we are still on crops and before inventory tutorials. Will you cover a couple stats on farmer experience growth to unlock new seeds as they ship out the crops to town? Figure one of the NPC's could be a delivery worker on the farm :)
Ah, that's an interesting idea! Though I actually think it would make more sense to implement experience after the inventory, since planting/picking/tending the crops would probably be the actions that would get you XP.
So my first thought was could we not save xx/yy position in the crop instance and get a list of all instances and just iterate through them, but then I found there doesn't seem to be a get all instances you would have to iterate through instance_find() for instance_number() times. So it might actually be better with the grid since I don't know the efficiency of instance_find()
In getting odd things happening. The crops are not saving the right growth state. Also if I leave planting mode on I get an error in the draw event. Can you post a copy of the gms file so I can compare code?
Well done! And yes, when leaving planting mode on and exiting the room, it will throw an error. We want to confine planting to only the farm room. We'll fix this soon!
Just finished watching your tutorial. just love seeing your tutorials. I am curious why you used a "repeat" loop and didn't use a "for" loop. very good tutorial as usual. Also have a comment about the saving of crop growth in a data grid. while you are in the other room the crop data is in the grid but it stops aging. if you were to stay away from the farm room for an extended period of time the crops would not have grown at all while you were gone unless you add code to update the crop data in the grid when you are not in the room. Hope I'm not getting ahead of you and that is something in upcoming tutorials.
Cheers Ron! No real reason, I just prefer how repeat loops look. It's clearer to me what's actually going on every loop. About the crops aging - yes, this is true! That is indeed something we will be addressing in later tutorials -- the current "hit G to grow" stuff was just temporary so that we could visualise what was going on. Soon we'll pair it with a day/night cycle and have THAT controlling the growth. Also realised I made a mistake in the vid -- entering the room actually increments the crop +1 day old... whereas it should just be updating its growth stage. But no matter, we'll fix this next time!
any loop can lead to endless loops, but repeat loops in game maker studio are not likely because you specify how many times to repeat the loop, and not the condition that would end the loop
I found a slight error in the growth stage code, when pressing G the crops get to max growth stage but don't sparkle until 1 more press of G (1 extra day). So 12 days of growth for tomatoes (4 stages) will actually take 13 days to sparkle. Seems that the else statement in the code needs to be changed to an if statement for this to work correctly! Here is the code (replace in object "crops" step event) - if (instance_exists(obj_crop) and keyboard_check_pressed(ord("G"))) { with (obj_crop) { if (growth_stage < max_growth_stage) { days_old += 1; growth_stage = days_old div growth_stage_duration; if (growth_stage == max_growth_stage) { fully_grown = true; alarm[1] = 1; } } } }
I know this video is old by now, but I have to ask. Do the crops age even when you aren’t in the room? I haven’t finished the video yet, so the answer may come, but I know in a lot of games, it is beneficial to have your crops grow even if you are away. Thanks!
Working through this, I keep getting a dividing by 0 error with growthStageDuration whenever trying to enter back into the room when trying to redraw what growth stage they are at. It works at the stage where you enter back into the room and they're still dirt mounds. But if I hit my growth key, the error pops up, or when we make it trigger automatically by entering the room, the error hits. It thinks for some reason my growth stage number is 0 because that's what we have it set to in obj_crop Create events.
I seem to have fixed it by changing growthStageDuration = 0; from the Create event within obj_crops to growthStageDuration = crops.ds_crops_types[# 0, cropType];
Not sure if it's just a mistake I've made compiling all the code but the corn disappears every time I press G after it's fully grown. I changed the scr_create_crop_type to (4, 50) and that seems to have fixed the disappearing issues but the sparkle won't appear when it's fully grown unless "G" is pressed one more time. Let me know if you're having the same issue and if not I'll have to go over all the code to see what I messed up lol
Ah that sounds odd! I'm not having this problem. It sounds like there might be an issue with the bit of code that's supposed to prevent it from increasing its growthStage once it hits the maxGrowthStage. If you can't find the problem, feel free to send me your project file at friendlycosmonaut@gmail.com, and I can take a look! :)
With this Room Start set up are we not adding +1 to the days_old variable every time we enter a room? And now I seem to be having a problem with my crops disappearing after I switch rooms a few time and they're fully grown aha Just my luck.
Sorry for spam commenting lol I ended up fixing the problem by removing the "else" function and replacing it with "if growth_stage = max_growth_stage { (sparkle alarm) } And before that instead of using the less than symbol I use "if growth_stage != max_growth_stage { " I have no idea why this fixed it... I mean it's doing the same thing, but hey it works now. Also removed the "days_old +=1;" from the Room Start Event. Might be because I'm now using the Mac version and it is quite buggy at times. :/
Help 15:45growthStageDuration = crops.ds_crops_types[# 0 ,cropType]; I entered the code but function "create_crop_type" expects 2 arguments, 3 provided
I'm getting a odd error in the "Room start" event :it's saying that it's no value in the 23-24 line(don't remember the exact line) I don't understand why could you anyone help Here the error located = growthStage = firstGrowth + (daysOld divgrowthStageDuration);
So i'm experiencing a bug with this script that's causing the crops to spawn double in number every time i enter/exit the room. after just a few enters/exits, there are so many instances that the game becomes unplayable. Has anyone else experienced this bug? the respawn script doesn't seem to be running multiple times. the data structure is being deleted between rooms. edit: the bug was causing an additional crop to be spawned at the 0,0 coordinate every time the respawn object script was run. setting the 0,0 grid coordinate to -1 the line before the crops loaded in seems to have fixed it.
Just make the crop obj persistent do in the Crop step event at the very first line "if(room != rm_farm) exit;" and at the draw event "if(room != rm_farm draw_set_alpha(0); ". This way it won't hurt the performance much and it's easier to work with.
fix for this? trying to index a variable which is not an array at gml_Object_crops_StartRoomEvent_1 (line 6) - if (ds_crops_data [# 0, 0] != -1){ not working in gm 1.4 :D
I get a crash after finishing the tutorial if you change room while still in planting mode. After debugging, it seems to be because there is still a draw event for the crops object that happens after room end, which I wouldn't expect. I have fixed it by changing the check at the top of our draw script in the crops object to be if(!plantingMode or !ds_exists(ds_crops_instances, ds_type_grid)) { exit }
First of all, thank you! Your video tutorials have been a huge help for teaching me how to code. I've been unable for weeks now to figure out how to save and load (using ini files) when it comes to this crop system. The crops are persistent when entering/leaving the room, but not when I close and reload the game. Has anyone been able to figure out how to save/load between game sessions?
for the problem having crop spawn at the left top of the room after changing room; just delete argument0, argument1 etc and give them specific names and declare them inside the function respawn_crop(_x, _y, _z, _t). that's it
I need this answered ASAP... I am having a lot of trouble on this for some reason. I have rewatched and rewatched this video, but after looking over my code to see any slight mistakes, I am still unable to get my crops respawned in the next room. I seriously don't know what I did wrong, my script is fine, i did the fixing in the room start. I dont know what I did!
The "new script function" is probably the problem. check for misspells and check if you named function as respawn_crop(grid_x, grid_y, crop_type, days_old). help.yoyogames.com/hc/en-us/articles/360005277377%20for%20more%20information the link show you how scripts works these days
@@athemulu did this work for you? I just finished this episode, and I am having the same issue you described. No syntax or spelling errors that I can find, the game runs fine but does not respawn my crops. I reformatted the script as @Simply Amazing suggested, but its still not working. EDIT: I pasted the following code into the Room Start event for the Crops object, right beneath the "//Respawn the crops" header: if(ds_crops_data[# 0,0] == -1) {show_debug_message("THE GAME THINKS DS_CROPS_DATA[# 0,0] == -1");} and it is displaying the message. so my game still has no data ever written into the ds_crops_data by the time I exit the house and return to the farm. Now I'm investigating my Room End event to see if the answer to WHY my crops arent being stored when I leave lies there.
@LINDSEY MORAN unfortunately, no. I got discouraged and left it alone for a while. Here's the notes I took to try to remember my place when I return to it: "The game knows there were crops on the farm, and how many, and does store them when I leave. But the game also thinks that every location in the crop instance grid has a value of 0, so it never enters the loop to feed the values into the crop data grid. So when I come back to the farm, presumably, the game *would* redrawn my crops, but it ate the data by failing to store it elsewhere before destroying it." So the question i was working on at that time was, "why does the game store crop instances as 0?" Sorry for the late reply. Have you had any progress?
@@loganjudy6776 @LINDSEY MORAN I had the same issue and actually had the same sort of issue after an earlier video. @DocEducation on the comments for video 7 posted a solution that worked to fix both of them. I believe the problem has to do with us using a newer version of gms than what is used in the video here is the solution. In respawn_crop change crop_type and days_old to inst.crop_type and inst.days_old //Give crop its characteristics with(inst){ inst.crop_type = argument2; inst.days_old = argument3; growth_stage_duration = crops.ds_crops_types[# 0, crop_type];
Kind of confusing you said you did that with the "Pressed G" but when and where? Did i miss that ? Cause after that part everythings messed up and when i re-enter the farm room after planting something i get this error: FATAL ERROR in action number 1 of Other Event: Room Start for object crops: DoRem :1: undefined value at gml_Object_crops_Other_4 (line 25) - growthStage = firstGrowth + (daysOld div growthStageDuration);
Yeah i missed a video, but now another problem after setting ds_crops_types = -1; ds_crops_instances = -1; instead of = 0; it always crashes before the game even starts with the error: Data structure with index does not exist. at gml_Script_create_crop_type (line 18) - ds_crops_types[# i, yy] = argument[i];
Looping through the grid? Hmm, I went through this part a bit faster since we've used a similar loop a couple times in the last two videos. Was it too fast?
So wouldn't it be better to store a "Planted on" date and a "current age" date. That way time could pass while you're not in the crop room but when you return the crops will have aged properly?
Hmmmm! I'm about to go over a change to this so that we're altering the GRID directly instead of the crops, but this would be a good way to do it too! If you're confident, you could definitely go ahead and code it that way.
I love this tutorial series to learn stuff from GMS, but when it now gets to this point I need to check what features have been added since 2017. The amount of spaghetti and downright ugly code you need to write to accomplish something like this is disheartening and pretty much shows you should not use GMS for data driven games.
Hey guys -- I made a mistake in the video by forgetting to alter the "growing" code when we ENTER the room. As it stands, since we just copy-pasted the code from the pressing "G" event, entering a room will also increment the number of daysOld. Which makes no sense! We'll fix this in the next-next video (I've already recorded the next one unfortunately), but for now, if you want to fix it, change the code to this: pastebin.com/PjM8smwZ
I love carrying on with this series after watching the view counts/like counts drop over the last 4 videos. It makes me feel like we're the few the proud who are still going cus we really wanna learn everything we can ha
So happy to see this video pop up today! It's really been a joy following the series so far. Eagerly awaiting the next one!
Edit: I noticed that if I was in planting mode and transitioned rooms while crops were currently growing, my game would crash. Omitting the "ds_grid_destroy(ds_crops_instances);" at 8:42 seems to have fixed it although I'm not savvy enough to know if it will cause any issues down the road. Super minor but I thought I'd share in case anyone experienced the same thing. Cheers!
I had the same issue. I tried adding "if planting planting = !planting" just above "ds_grid_destroy(ds_crops_instances);" in the Room End event. Seems to work.
The draw event is running even though we destroy the DS. It's creating an error because it no longer exists.
Just had the same problem. Felt smart, fixed it myself, came to post a comment, found this from 4 months ago. Sigh.
Second this to fix the related crash. Crops are not persisting, however.
A little fix that maybe is adressed later, but i've encountered here and maybe someone else could find it here too and find this helpfull. When you leave the room on planting mode the game crashes because the draw event on the crop object doesnt find a ds_crops_instances grid. We delete it on room end and only recreate it if we are on rm_farm. I fixed it by adding: if(room != rm_farm) exit; on the beggining of the draw event on the crop object. But now if you click on the other room you crash the game too, so i've added: and room = rm_farm on the condition to plant on the step event, so planting is only alowed in the farm room. Sorry if my english is not so good. Thanks for the videos! ;)
Thank you, I'm sure other people will run into this! We fix this a little bit later on, but it's good to have a solution now. :)
I've encountered your solution now on P12, add if(room != rm_farm) {planting = false; exit;} on the step event of the crops object. Simpler and better than my solution, so i leave it here.
aww thank you:)
...hey Asov, thanks for sharing the solution thank you so much :)
encountered the same error, i added an event to the transition collision check to turn off planting mode instead.
Really appreciate this content, because I've felt like I've been stumbling around in dark with most of my gamemaker process.
Love this series
Hello - you're doing a good job with your tutorials. On persistence, you could also set the room to be persistent to retain the non-persistent instances created in that room.
This method seems infinitely simpler. Is there a downside to this?
Thank you for taking the time to do this - very helpful!
Firstly, let me say what a brilliant set of tutorials these are! Well done! Looking forward to seeing how they develop. But I think I found a couple small things, maybe one small glitch. Which occurs about here in the tutorials, once we implement the growing system. Once the grids are in place, once you press P for planting mode, if you drag the mouse down to the bottom of the camera and viewport (noting that for me this occurs at the bottom of the room), I seem to draw a red box (ie no soil here to plant in) mostly off screen which provides the following output in the console: Grid 3, index out of bounds writing [1,28] - size is [47,28]
The 1 in [1,28] will change depending on which column the mouse is in, 1 is to the first left, which will increment up by 1 each cell to the right I move...
The second thing is more of a “glitch” perhaps. I’m pretty sure my code is right up to this point. But, if you again press P for plant mode, and drag slowly to the left most side of the viewport such that the box / selected crop is up against the edge of the room / viewport - while initially a red box, returning the debug message of no soil - if you slowly drag the mouse off the edge of the viewport, there is a small window you have presented to you where the box turns green (and to be clear this box is fully in the viewport and camera, it doesn’t offer any option to construct that box out of view, as per the issue above) and while the cursor is ever so slightly off the viewport you can press on that green box and plant a crop where there is no soil to do so. This is remembered and recalled accurately if you change rooms and come back. I tested this on the right most side of the room, and find the same Grid console message as above, this time changing the second digit in the square brackets not the first (as was the case when you pull the mouse off the bottom of the viewport).
I’ve been playing with it for 15 mins and I think it’s some combination of the cell and data variables in the instance_create_crop script which is called once the mb_left is pressed. Or, I’ve got a feeling that perhaps it’s related to the size of the room, viewport and camera all needing to be in increments of 32 (cellSize)... any thoughts would be appreciated - and apologies if this has already been picked up or sorted in later tutorials.
You rock, cheers
Apologies for the late reply, I was away on a trip!
Ah this will be to do with the fact that we made the grid to "fit" the room size. Since the "origin" of the x and y axis is at (0,0), and then stretch down and to the right, those "out of bounds" errors appear at the bottom and right boundaries. As for the "glitch" - ah I can reproduce this in my project too. We will definitely need to return and fix these issues in later tutorials, so thank you for letting me know!!
I'll include a fix more formally in the tutorial, but for now, this seems to fix the issue:
Exactly as you say, the problem is in the instance_create_crop script, and is actually a quirk of how the tilemap function works. We were checking if there was soil absent by seeing if the "data" from the tilemap_get_at_pixel (at the point we click) is equal to 0. But the problem is, if there is NO tile at ALL (like for positions outside the room), it's actually = -1. But, since -1 != 0, it was allowed to pass as if soil was present. So we could change this to instead check if(data
Enjoying this series. Thanks for all your work.
Awesome work again! Please don't stop repeating bits of what we have learned in the previous parts, the quick references are a great refresher (like you seem to do so far) ;) Especially with array stuff, let alone with multiple grids that work together, it can get very abstract fast if you need to process a lot of new information on top of that. So, again, I really appreciate the images - I would be lost if I had to keep that in my mind while following along (and would not actually learn anything but just blindly copy your code without understanding it).
And if I may make a suggestion (after saying that I really like the pace of your videos and their requirement of my commitment); Sometimes you skip/speed up tedious bits, but I feel they go a bit unnoticed and so I miss out on valuable info. I do not constantly look at the video, because I try to predict what the next piece of code will be or whatever. So maybe you could describe a bit more what is happening on screen. Like "So if we look at the excel sheet again.." so i know i have to look up instead of getting to know what i typed. Or when you speed up copy/paste code maybe a bit more pause in between or a short comment to indicate what you currently are pasting if you skip over it. It is a lot of new info (like this comment hehe) so yeah please keep repeating/refering until we are sick of it. Then we know for sure! I'm sure I won't need the extra nudges when I'm more advanced. But it would be nice to stay in a flow without searching for something that I've missed out on. Sorry for the ultra long comment, I just want to clearly state that it's a minor thing again and that your work and effort is amazing. Thank you. :)
Thanks so much Robin! I'm glad you haven't found the repetitions tedious, I'm trying to strike a balance but I know it's almost pointless since some viewers might not have watched previous episodes, some are at different experience levels, etc. Perhaps erring on the side of "too much explaining is better than too little" is best!
Ah, that's a great suggestion!! Unfortunately I've already recorded the next video, but I'll try to do this next time. I hadn't really thought about it, but I definitely remember having the same troubles when watching other people's tutorials: looking at my project and missing something on the screen.
Always lovely to hear from you - you're very kind, and I really appreciate the feedback/suggestions :)
FriendlyCosmonaut Yeah I can understand that it's hard to judge the pacing as when you are a more advanced and experienced. But it's easier to pickup on things when you are aware of it's usage. And this for me personally is learning a totally new foreign language. And I am used to doing programming is a different way. So yeah, I would much rather feel that I already know it, than forget what I have learned.
And the people who have not watched enough to get your short references should not be surprised. This is part 10 of a series, if they need a refresher I'm sure they can get what they need from it or should be willing to search it out. But the intention is to build a farm together from the ground up, at least that's what I assume. (And hey maybe you will get even more views this way as an added bonus ;p )
But I'm happy to hear that my feedback is well received! Keep it up :)
If you get a divide by 0 error when reentering the farm, make sure you didn't make a mistake with the respawn_crop function. I spent half an hour troubleshooting only to realize I put "crops.ds_crops_instances" instead of "crops.ds_crops_types"...
I have one issue: when I press p in the house it crashes. I fixed that by only allowing to go into plant mode while in rm_farm. But when i enter the house while planting is active it crashes too because ds_crops_instances doesnt exist. I am pretty new so idk how to fix this. Any ideas?
EDIT: I fixed it by putting
if(room != rm_farm){
planting = false;} on top of the planting code.
Could someone please help?
I get this error when I change rooms: Data structure with index does not exist.
at gml_Object_crops_Draw_0 (line 9) - var cell = ds_crops_instances[# gx, gy];
It was working fine at the end of the previous video but suddenly after adding the code to make the crops persistent that line broke.
I got this too. The thing that's causing it for me is if I have the "Plant Crop" button enabled. If you see the crops on your mouse cursor, press P to remove it and then try zoning and coming back. Other than this strange problem, it's working. Another person said they got the same problem and that it'll be fixed soon. Perhaps its fixed in one of the later vids for this series.
@@Duran8998 Thank you for your reply!! It was driving me crazy.
Hi! I have a silly question 😅 Why do we have to destroy a data structure when the game ends? Doesn't it automatically get destroyed when the game ends?
So strange! I've triple-checked ALL code but still, when I plant stuff, then go to leave rm_farm to check persistence, I get an error about:
"Data structure with index does not exist.
at gml_Object_crops_Draw_0 (line 11) - var cell = ds_crops_instances[# gx, gy];
"
So I think I must have made a typo in code or something, but I can't find it! I'll try tomorrow
I've had the same error too. In the crops object in the room end event add the following lines:
if (planting){
planting = false;
}
So it turns off planting mod before leaving room
I don't know if it will be fixed in the next videos, but this is a quick solution I've found
Like your way of saving persistent data between rooms. While we are still on crops and before inventory tutorials. Will you cover a couple stats on farmer experience growth to unlock new seeds as they ship out the crops to town? Figure one of the NPC's could be a delivery worker on the farm :)
Ah, that's an interesting idea! Though I actually think it would make more sense to implement experience after the inventory, since planting/picking/tending the crops would probably be the actions that would get you XP.
So my first thought was could we not save xx/yy position in the crop instance and get a list of all instances and just iterate through them, but then I found there doesn't seem to be a get all instances you would have to iterate through instance_find() for instance_number() times. So it might actually be better with the grid since I don't know the efficiency of instance_find()
In getting odd things happening. The crops are not saving the right growth state. Also if I leave planting mode on I get an error in the draw event.
Can you post a copy of the gms file so I can compare code?
Fixed: I had 4 instead of 3 on the DS for the growth stage. It saves right now.
Well done! And yes, when leaving planting mode on and exiting the room, it will throw an error. We want to confine planting to only the farm room. We'll fix this soon!
Just finished watching your tutorial. just love seeing your tutorials.
I am curious why you used a "repeat" loop and didn't use a "for" loop. very good tutorial as usual.
Also have a comment about the saving of crop growth in a data grid. while you are in the other room the crop data is in the grid but it stops aging. if you were to stay away from the farm room for an extended period of time the crops would not have grown at all while you were gone unless you add code to update the crop data in the grid when you are not in the room. Hope I'm not getting ahead of you and that is something in upcoming tutorials.
Cheers Ron!
No real reason, I just prefer how repeat loops look. It's clearer to me what's actually going on every loop.
About the crops aging - yes, this is true! That is indeed something we will be addressing in later tutorials -- the current "hit G to grow" stuff was just temporary so that we could visualise what was going on. Soon we'll pair it with a day/night cycle and have THAT controlling the growth.
Also realised I made a mistake in the vid -- entering the room actually increments the crop +1 day old... whereas it should just be updating its growth stage. But no matter, we'll fix this next time!
The problem with repeat, it can lead to endless loops if not careful.
any loop can lead to endless loops, but repeat loops in game maker studio are not likely because you specify how many times to repeat the loop, and not the condition that would end the loop
How would i implement a harvesting system?
I found a slight error in the growth stage code, when pressing G the crops get to max growth stage but don't sparkle until 1 more press of G (1 extra day). So 12 days of growth
for tomatoes (4 stages) will actually take 13 days to sparkle. Seems that the else statement in the code needs to be changed to an if statement for this to work correctly!
Here is the code (replace in object "crops" step event) -
if (instance_exists(obj_crop) and keyboard_check_pressed(ord("G")))
{
with (obj_crop)
{
if (growth_stage < max_growth_stage)
{
days_old += 1;
growth_stage = days_old div growth_stage_duration;
if (growth_stage == max_growth_stage)
{
fully_grown = true;
alarm[1] = 1;
}
}
}
}
I know this video is old by now, but I have to ask. Do the crops age even when you aren’t in the room? I haven’t finished the video yet, so the answer may come, but I know in a lot of games, it is beneficial to have your crops grow even if you are away. Thanks!
They will! Though I can't remember if it was done in this video or in a coming one.
Working through this, I keep getting a dividing by 0 error with growthStageDuration whenever trying to enter back into the room when trying to redraw what growth stage they are at. It works at the stage where you enter back into the room and they're still dirt mounds. But if I hit my growth key, the error pops up, or when we make it trigger automatically by entering the room, the error hits. It thinks for some reason my growth stage number is 0 because that's what we have it set to in obj_crop Create events.
I seem to have fixed it by changing growthStageDuration = 0; from the Create event within obj_crops to growthStageDuration = crops.ds_crops_types[# 0, cropType];
Not sure if it's just a mistake I've made compiling all the code but the corn disappears every time I press G after it's fully grown. I changed the scr_create_crop_type to (4, 50) and that seems to have fixed the disappearing issues but the sparkle won't appear when it's fully grown unless "G" is pressed one more time. Let me know if you're having the same issue and if not I'll have to go over all the code to see what I messed up lol
Ah that sounds odd! I'm not having this problem. It sounds like there might be an issue with the bit of code that's supposed to prevent it from increasing its growthStage once it hits the maxGrowthStage. If you can't find the problem, feel free to send me your project file at friendlycosmonaut@gmail.com, and I can take a look! :)
FriendlyCosmonaut thanks! I'll try and look over everything again and see where I went wrong...
Ahhhhh found it! Mixed up max_growth_stage and growth_stage_duration! My bad... Thanks for these awesome tutorials! You really know your stuff.
With this Room Start set up are we not adding +1 to the days_old variable every time we enter a room? And now I seem to be having a problem with my crops disappearing after I switch rooms a few time and they're fully grown aha Just my luck.
Sorry for spam commenting lol I ended up fixing the problem by removing the "else" function and replacing it with "if growth_stage = max_growth_stage { (sparkle alarm) } And before that instead of using the less than symbol I use "if growth_stage != max_growth_stage { " I have no idea why this fixed it... I mean it's doing the same thing, but hey it works now. Also removed the "days_old +=1;" from the Room Start Event. Might be because I'm now using the Mac version and it is quite buggy at times. :/
Hi could you please show how to pick a crop // delete the crop from the grid.!!
Help 15:45growthStageDuration = crops.ds_crops_types[# 0 ,cropType];
I entered the code but function "create_crop_type" expects 2 arguments, 3 provided
The create_crop_type() script should only accept 2 arguments or inputs into the script. You might have accidentally entered an additional argument.
I'm getting a odd error in the "Room start" event :it's saying that it's no value in the 23-24 line(don't remember the exact line) I don't understand why could you anyone help
Here the error located = growthStage = firstGrowth + (daysOld divgrowthStageDuration);
your issue is that you didn't add a space between div and growthStageDuration
ocated = growthStage = firstGrowth + (daysOld div growthStageDuration);
@@andrewwang1797 it´s been one year, you don´t need to awnser, but thanks...
@@notprqn422 At least they tried to help?
So i'm experiencing a bug with this script that's causing the crops to spawn double in number every time i enter/exit the room. after just a few enters/exits, there are so many instances that the game becomes unplayable. Has anyone else experienced this bug?
the respawn script doesn't seem to be running multiple times.
the data structure is being deleted between rooms.
edit: the bug was causing an additional crop to be spawned at the 0,0 coordinate every time the respawn object script was run. setting the 0,0 grid coordinate to -1 the line before the crops loaded in seems to have fixed it.
Just make the crop obj persistent do in the Crop step event at the very first line "if(room != rm_farm) exit;" and at the draw event "if(room != rm_farm draw_set_alpha(0);
". This way it won't hurt the performance much and it's easier to work with.
But that makes the player invisible
@@bioticgamer4976 No, it just exits the draw event of the crop object, not the draw event in general.
fix for this?
trying to index a variable which is not an array
at gml_Object_crops_StartRoomEvent_1 (line 6) - if (ds_crops_data [# 0, 0] != -1){
not working in gm 1.4 :D
I get a crash after finishing the tutorial if you change room while still in planting mode. After debugging, it seems to be because there is still a draw event for the crops object that happens after room end, which I wouldn't expect. I have fixed it by changing the check at the top of our draw script in the crops object to be if(!plantingMode or !ds_exists(ds_crops_instances, ds_type_grid)) { exit }
Ah, yes! This is addressed a little later on in the series, but great job for catching it early.
FriendlyCosmonaut ah! Sounds good. Thanks again for the tutorial series!
First of all, thank you! Your video tutorials have been a huge help for teaching me how to code. I've been unable for weeks now to figure out how to save and load (using ini files) when it comes to this crop system. The crops are persistent when entering/leaving the room, but not when I close and reload the game. Has anyone been able to figure out how to save/load between game sessions?
I 'm so happy.
for the problem having crop spawn at the left top of the room after changing room; just delete argument0, argument1 etc and give them specific names and declare them inside the function respawn_crop(_x, _y, _z, _t).
that's it
I need this answered ASAP... I am having a lot of trouble on this for some reason.
I have rewatched and rewatched this video, but after looking over my code to see any slight mistakes, I am still unable to get my crops respawned in the next room. I seriously don't know what I did wrong, my script is fine, i did the fixing in the room start. I dont know what I did!
The "new script function" is probably the problem. check for misspells and check if you named function as respawn_crop(grid_x, grid_y, crop_type, days_old). help.yoyogames.com/hc/en-us/articles/360005277377%20for%20more%20information the link show you how scripts works these days
@@simplyamazing428 thank you
@@athemulu did this work for you? I just finished this episode, and I am having the same issue you described. No syntax or spelling errors that I can find, the game runs fine but does not respawn my crops. I reformatted the script as @Simply Amazing suggested, but its still not working.
EDIT: I pasted the following code into the Room Start event for the Crops object, right beneath the "//Respawn the crops" header:
if(ds_crops_data[# 0,0] == -1) {show_debug_message("THE GAME THINKS DS_CROPS_DATA[# 0,0] == -1");}
and it is displaying the message. so my game still has no data ever written into the ds_crops_data by the time I exit the house and return to the farm. Now I'm investigating my Room End event to see if the answer to WHY my crops arent being stored when I leave lies there.
@LINDSEY MORAN unfortunately, no. I got discouraged and left it alone for a while. Here's the notes I took to try to remember my place when I return to it:
"The game knows there were crops on the farm, and how many, and does store them when I leave. But the game also thinks that every location in the crop instance grid has a value of 0, so it never enters the loop to feed the values into the crop data grid. So when I come back to the farm, presumably, the game *would* redrawn my crops, but it ate the data by failing to store it elsewhere before destroying it."
So the question i was working on at that time was, "why does the game store crop instances as 0?"
Sorry for the late reply. Have you had any progress?
@@loganjudy6776 @LINDSEY MORAN
I had the same issue and actually had the same sort of issue after an earlier video. @DocEducation on the comments for video 7 posted a solution that worked to fix both of them. I believe the problem has to do with us using a newer version of gms than what is used in the video here is the solution.
In respawn_crop
change crop_type and days_old to inst.crop_type and inst.days_old
//Give crop its characteristics
with(inst){
inst.crop_type = argument2;
inst.days_old = argument3;
growth_stage_duration = crops.ds_crops_types[# 0, crop_type];
Kind of confusing you said you did that with the "Pressed G" but when and where? Did i miss that ? Cause after that part everythings messed up
and when i re-enter the farm room after planting something i get this error:
FATAL ERROR in
action number 1
of Other Event: Room Start
for object crops:
DoRem :1: undefined value
at gml_Object_crops_Other_4 (line 25) - growthStage = firstGrowth + (daysOld div growthStageDuration);
Yeah i missed a video, but now another problem after setting
ds_crops_types = -1;
ds_crops_instances = -1;
instead of = 0;
it always crashes before the game even starts with the error:
Data structure with index does not exist.
at gml_Script_create_crop_type (line 18) - ds_crops_types[# i, yy] = argument[i];
what was the fault? I know it is 4 years ago but I also get this error maybe you can remeber
Hi cosmonaut. Can maybe sometime do a quick few top down shooter tutorials? Good job BTW👍
Haha, perhaps in the future! Thank you :)
top top top!
THANK YOUUUUUUUUUUUUUUUUUU
6:20 is where you completely lost me
Looping through the grid? Hmm, I went through this part a bit faster since we've used a similar loop a couple times in the last two videos. Was it too fast?
FriendlyCosmonaut I'll look through it again, but ds usually confounds me anyway
No worries, they're tricky!
So wouldn't it be better to store a "Planted on" date and a "current age" date. That way time could pass while you're not in the crop room but when you return the crops will have aged properly?
Hmmmm! I'm about to go over a change to this so that we're altering the GRID directly instead of the crops, but this would be a good way to do it too! If you're confident, you could definitely go ahead and code it that way.
-"Hey guys, today we're gonna make our crops persistent"
*Clicks on the "Persistent" checkbox*
-"And that's all for today guys"
jk, nice tutorial :)
I love this tutorial series to learn stuff from GMS, but when it now gets to this point I need to check what features have been added since 2017. The amount of spaghetti and downright ugly code you need to write to accomplish something like this is disheartening and pretty much shows you should not use GMS for data driven games.