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

Making Five Nights at Freddy's fangame, how do I add doors?

M

Medieval Ducky Official

Guest
I'm making a fan game of fnaf (I'm not going to talk about what it is) And I'm trying to make the door function (I've done the sprites for the door buttons and the door closing). How do I program it to close?
 

Llama_Code

Member
If your expecting a reply then you should make sure you give complete information. I have never played FNAF so I have no clue how a door in that game behaves, and it shouldnt be the burden of your potential help to look it up and figure it out.

What do you want the door to do? What have you tired? What's not working? What kind of game is it? My best guess it it's an adventure game, and then it could be as simple as changing an image index to closed sprite. But since you didn't give enough information, can't really help you.

Also remember this is a volunteer community forum, so answers can vary from time of day and depending if anyone is on that can help you.
 

Soso

Member
Create event. [obj_door]
door_state = "closed";

Step event
If door_state = "closed"
{sprite_index = spr_door_closed;}

If door_state = "open"
{sprite_index = spr_door_open;}
 
M

Medieval Ducky Official

Guest
Create event. [obj_door]
door_state = "closed";

Step event
If door_state = "closed"
{sprite_index = spr_door_closed;}

If door_state = "open"
{sprite_index = spr_door_open;}
Now what about the button that closes it?
 
Last edited by a moderator:

Soso

Member
Ok in your open button object

And select the mouse left click event

Then put this code

{obj_door.door_state = "open";}

how many buttons are you using for the door and are they seprate objects?
 
M

Medieval Ducky Official

Guest
Ok in your open button object

And select the mouse left click event

Then put this code

{obj_door.door_state = "open";}

how many buttons are you using for the door and are they seprate objects?
Two. Red for opened door and green for closed.
 
M

Medieval Ducky Official

Guest
Also, the scripting comes up with errors. How do I fix this?
 
To change the red button to green there are a few ways. One is to have a button sprite with 2 images(image 0 being a red button and image 1 being the green button) set the image_speed and image_index to 0 in the create event of the button. when you want to display the green button, Just set the image_index to 1.

Or, you could Just have two different sprites, One red button, One green button. in your button object, set the sprite_index to the sprite you want to display.
 
That is saying your code is written incorrectly, specifically the "if" statement. I'm not a mind reader...where is your code I asked you to post?
 
This is not really asking for help. You only want someone to write the code for you and you seem to have zero intrest in learning how the code work and what it does. You should ask for someone to work with you instead of asking for code.

Correct me if I'm wrong.
 

Soso

Member
Ok i see your problem in your if statement you put a ; remove that only put them after each command with in the braces

Also you didnt use braces { to close your code you need those

If door_state = "closed"
{ sprite_index = spr_door_close ; }

So remember no ; after your if condition
Only after the codes your executing inside the braces.

[Example]
If door_state = "broke"
{sprite_index = spr_door_ broke ;
Image_speed = 0.5 ;
door_level +=1 ; }

Also watch your capitalization you had a capital S for sprite_index it has to be lower case you will know its correct when in turns red in code

Now spr_door_open didnt turn red in your code cause it dosent match the sprites resource name which im guessing you named door. spr in shorten lingo for sprite
As is obj for object

So you need to rename your sprite in the resource tree to spr_door_open however you could just put door if you wanted to as long as thats what you named that sprite
 
Last edited:
M

Medieval Ducky Official

Guest
To change the red button to green there are a few ways. One is to have a button sprite with 2 images(image 0 being a red button and image 1 being the green button) set the image_speed and image_index to 0 in the create event of the button. when you want to display the green button, Just set the image_index to 1.

Or, you could Just have two different sprites, One red button, One green button. in your button object, set the sprite_index to the sprite you want to display.
I'm a little confused about the sprite index part, to be honest -_-.
 
sprite_index controls what sprite will be drawn for the object. By default, your object Will draw the sprite that you gave it in the object editor window. however, if you want to change what sprite game maker Will draw for your object, you can Use sprite_index to do that.

The name you give your sprites in the resource editor also function as the names you use to change the sprite_index.

So if you made two sprites and called them spr_green_ball and spr_red_ball, in GML the code you would Use to change the sprite is:

sprite_index = spr_green_ball

or

sprite_index = spr_red_ball

hope this helps.

I suggest you read the documentation if you haven't already then come back and ask if anything else is still not clear.

EDIT: There are other ways to draw sprites directly, but don't want to over complicate things as they are.
 
The code @Soso gave you is basically :
Code:
obj_door.door_state = "closed"
The code you are using is:
Code:
obj_door.door_state = closed
See the difference? Just trying to help you figure it out for yourself, so you can learn for next time.
 

FrostyCat

Redemption Seeker
Do you know the difference between obj_door and objdoor?

So far every single error on this topic has to do with your careless attitude towards reading what you typed. If spotting missing characters is really such a problem for you, I suggest that you get another hobby that doesn't involve reading.
 
The thing about coding is that the spelling of everything needs to be exactly right. If you don't spell it correctly, GameMaker isn't able to guess what you meant. That means if you call something obj_door in the first place, you need to keep calling it obj_door everywhere else you want to use it.
 
M

Medieval Ducky Official

Guest
The coding worked perfectly, but the door sprite isn't changing.



P.S. Sorry if I'm frustrating some of you guys.
 

Attachments

I figure everyone has to start somewhere. I think that for what you are trying to achieve, it might be valuable for you to go through some of the gamemaker tutorials if you haven't already done so. They may help clear up a lot of the stuff you are trying to do here.
 
M

Medieval Ducky Official

Guest
I figure everyone has to start somewhere. I think that for what you are trying to achieve, it might be valuable for you to go through some of the gamemaker tutorials if you haven't already done so. They may help clear up a lot of the stuff you are trying to do here.
Alright, Thanks for the help.
 
Top