Collecting objects to move to next level

A

AnnaMullins009

Guest
Hi everyone,

In my game, obj_chef must collect three different foods from each level before he can go to the next one. However, I am not sure how to do this. The three food objects are:

obj_milo
obj_weetbix
obj_vegemite

I have created a door to the next level and I want this door to be locked or have an "invisible wall" in front of it before obj_chef collects the three food items.

SO basically I need some gml or instructions for collecting the objects and the invisible wall essentially lifting once they are collected.

Thanks!!
 

DarthTenebris

Definitely not a Sith Lord
First of all, it would be better both for you and others to post the code or dnd actions you have tried prior to posting. It will help you learn and potentially save othets some time by knowing what you have tried and if it doesn't work it can help others work out why.

To the point:
All you need is a variable check. Simply put:
Code:
obj_door Create Event:
open = false;

obj_door Collision with obj_player Event:
if (open == true) {
     room_goto(your_next_level); // Next level room name
}

obj_door Step Event:
if ((!instance_exists(obj_milo)) && (!instance_exists(obj_weetbix)) && (!instance_exists(obj_vegemite))) {
     open = true;
}
Destroy all food items on contact with player. You should know how to create and destroy objects via code by now. If you haven't, look up the functions instance_create() and instance_destroy() as those are very basic.

Hope I helped :)
 

The-any-Key

Member
You can have a persistent control object and set variables like:
Code:
Collected_milo=0;
When you collect you can add to the variable like
Code:
obj_control.Collected_milo+=1;
then you can use the control to check when you are done.
 
A

AnnaMullins009

Guest
First of all, it would be better both for you and others to post the code or dnd actions you have tried prior to posting. It will help you learn and potentially save othets some time by knowing what you have tried and if it doesn't work it can help others work out why.

To the point:
All you need is a variable check. Simply put:
Code:
obj_door Create Event:
open = false;

obj_door Collision with obj_player Event:
if (open == true) {
     room_goto(your_next_level); // Next level room name
}

obj_door Step Event:
if ((!instance_exists(obj_milo)) && (!instance_exists(obj_weetbix)) && (!instance_exists(obj_vegemite))) {
     open = true;
}
Destroy all food items on contact with player. You should know how to create and destroy objects via code by now. If you haven't, look up the functions instance_create() and instance_destroy() as those are very basic.

Hope I helped :)
Alright so I added what you suggested and I tried it out and it says there is an error with the (open == true) command with the collision event with the door and chef.

My current code in the obj_chef collision event with the obj_door is:

if (open == true) {
room_goto(Level_2);
}

if room=Level_1
room_goto(Level_2)
else if room=Level_2 and x<200
room_goto(Level_1)
else if room=Level_1 and x>600
room_goto(Level_2)
else if room=Level_2
room_goto(Level_3)

My current code in the obj_door create event is:

open = false;

My current code in the obj_door step event is:

if ((!instance_exists(obj_milo)) && (!instance_exists(obj_weetbix)) && (!instance_exists(obj_vegemite))) {
open = true;
}

The only code I have for my three foods is just the destroying the instance once it collides with obj_chef.

Any suggestions??
 

TheouAegis

Member
if other.open== true
{
if room=Level_1
room_goto(Level_2)
else if room=Level_2 and x<200
room_goto(Level_1)
else if room=Level_1 and x>600
room_goto(Level_2)
else if room=Level_2
room_goto(Level_3)
}
 

DarthTenebris

Definitely not a Sith Lord
Try changing room into room_get_name(room) and change Level_2 into "Level_2" (add double quotes).

EDIT:
Or put the code in obj_door colliding with chef instead of chef with obj_door. But do the above advice as well.
 

Slyddar

Member
You could also create a coloured sprite rectangle, then create an object, say o_doorlock, with this sprite and ensure it has whatever your wall/solid object as a parent, so the player can't walk through it. Untick the visible property on it and place it over your door. Inside it have three variables in a create event.

obj_milo_collected = false;
obj_weetbix_collected = false;
obj_vegemite_collected = false;

Then as the player collects an object, ensure you update the variables, eg o_doorlock.obj_milo_collected = true. Then in o_doorlock have a collision event with the chef that asks in the collision,
Code:
if obj_milo_collected and obj_weetbix_collected and obj_vegemite_collected {
   instance_destroy;
}
It will then destroy itself when it's true and let the player walk through. If you need an image change on the door, you can obviously do that too if required in the same code.
 
Top