Question about using a step event
Posted 11 August 2012 - 01:26 AM
I'm sorry that I'm new and not familiar with this program. I'm using the lite Windows version. I went through both tutorials that came with the game (a bouncing fruits game and a scrolling shooter) and made it through both (though the scrolling shooter one had several places where the author assumed the reader was familiar with certain functions that I was still unfamiliar with - but a couple Google searches got me through it). I've managed to get a start on my game, but I'm having a hard time getting a certain function to work.
Part of the game involves a building that falls into disrepair each night. I've created a day/night cycle using an object called 'night' which is just a giant black screen set at alpha 0.5 (I watched a tutorial on Youtube to figure that part out). I was able to set up a timeline which causes the 'night' object to be created every set interval and then destroyed again after a moment. This functions fairly smoothly for a day/night cycle.
What I'm having trouble with is convincing the building to be damaged when the night object appears. I thought it would a fairly simple matter of adding a step event with 'test instance count' from the control pane. I set it to 'if number of objects obj_night is equal to 1', then added start and end blocks underneath to destroy the 'wall' objects and replace them with damaged wall objects. (Technically, I use the 'create random' feature to make it about a 50% chance that each wall portion becomes damaged.) But when I test it, the night object appears as it should, but the walls do not change. I'm not sure what I'm doing wrong. To the best of my understanding, the 'step' event is supposed to constantly monitor, so I would think that it would notice when the night object appears and therefore cause the ensuing actions to occur. What am I missing?
Thank you so much for your help. I'm sorry again for bothering you. I tried to search and see if there was an answer to my question, but I was unable to find anything.
Posted 11 August 2012 - 02:00 AM
Posted 11 August 2012 - 02:12 AM
How exactly are you destroying and creating blocks? Is each wall a different object? Are you sure the object that you have the code in is in the room when night time comes around (since I'm not sure what object you have doing this)? You are destroying all wall objects and recreating each one?
Thank you very much for your response! What I had used before was a timer event which activated two actions: destroy the instance (under main1 tab) and create random under the same tab, using the 'relative' option to make sure that the damaged wall object was created in the same space. Using a timer, this worked perfectly every time. I technically could simply change all the timers to coincide with the night timeline, but I thought it would be a lot easier if I could just have the objects change when the timeline creates the 'night' object (that way, if I change my mind on the timing, I don't have to go and change the timing for every object).
Each wall is a different object. Originally, each wall was set on the timer to destroy itself and then create at random either a new wall or a damaged wall (about 50% chance). This worked perfectly. After I learned a bit more about timelines and how to create a day/night cycle (more below on that part), I thought it would be easier to make the walls respond to the night object's presence rather than a timer (see above). I deleted the timer, then added a 'step' event which tells it, if the number of object 'night' is equal to 1, to go through the destroy/create random cycle. I used start and end blocks before and after those two commands (destroy and create random) to make sure they were both tied into the 'test instance count' action. However, when the night object appears, the walls do not change. I watched it through two cycles just in case the 50% chance came up VERY lucky, but nothing changed in the second appearance of 'night,' either.
As for the 'night' object, I have an invisible object which also sets off timers. It is in the room. I gave it a 'create' event to set the night timeline. The night timeline then creates the object 'night' and destroys it after a second. I am not sure where the object is created. It's basically a sprite the size of the entire screen made completely of black with alpha set at 0.5 (so it basically darkens the entire game for a second, then returns to normal brightness; hence the appearance of day/night). I'm assuming the object is present because the screen does go dark at the correct timing when I test the game. But the wall objects do not respond as if the night object is present.
Posted 11 August 2012 - 02:21 AM
The only reason why your current method isn't working is that there is more than one night object being created (perhaps 2). You said the night lasts for about a second, but if you got your method to work, your code would run through multiple times causing more walls to be damaged than what you originally planned.
Posted 11 August 2012 - 02:30 AM
Posted 11 August 2012 - 03:04 AM
I'm not sure what I'm doing wrong. Or maybe this is just because I have the lite version? I'm not sure why timer 0 will function perfectly on the object but not on the timeline, which is attached to an object and set in the room.
Posted 11 August 2012 - 03:12 AM
Posted 11 August 2012 - 03:28 AM
Thank you. I changed the bubble to 'object' and made it the wall object. Now the damage happens as expected.
However... the damage happens a full second before the night cycle begins. Not sure why?
Posted 11 August 2012 - 04:57 AM
Posted 11 August 2012 - 12:43 PM
(though the scrolling shooter one had several places where the author assumed the reader was familiar with certain functions that I was still unfamiliar with - but a couple Google searches got me through it)
I just want to point out that if you press F1 in Game Maker, or click on the blue and white interrogation mark icon, the help file will pop up, which is basically a user manual, with all the functions. That should save you quite a few trips to Google.
Posted 11 August 2012 - 04:55 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users