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

Switching views if object exist

I

id07

Guest
Looking for input/advice, as I can't get this to work.

In create event:
if object_exists(x, y, obj_enemy_battle_attack) {
{
view_visible[0] = false
view_visible[1] = true
}
else
{
view_visible[0] = true
view_visible[1] = false
}

I dropped this into the room as a "view controller" object.

My goal is to change from one view that's following the player, to suddenly switch to a new view when an object is created on screen, and then switch back to the view following the player when it is destroyed. Getting errors:

Error : gml_Object_obj_view_trigger_CreateEvent_1(7) : unexpected symbol in expression

Error : gml_Object_obj_view_trigger_CreateEvent_1(7) : malformed assignment

Error : gml_Object_obj_view_trigger_CreateEvent_1(7) : symbol } expected

Error : gml_Object_obj_view_trigger_CreateEvent_1(9) : symbol } expected

Error : gml_Object_obj_view_trigger_CreateEvent_1(9) : symbol } expected
 

Baldi

Member
Well in the code you copied there are two "{" in the beginning.
You wrote
In create event:
if object_exists(x, y, obj_enemy_battle_attack) { //one
{ //two

But apart from that you are using object_exists which just checks wether that object is present in the game files, you want to know wether it is present in the room, for that use instance_exists(obj_enemy_battle_attack).
Also: both instance_exists and object_exists do not ask for coordinates.

EDIT: And should you ever want to know whether an instance exists at a specific position, use "if instance_place(x, y, obj)"
 
I

id07

Guest
Thaaaaank you! Appreciate the help!
I also found I needed to put the code in a Step Event and not Create
:3
 

Baldi

Member
Oh yes I overlooked that part. Simply put everything you want to be done the entire time you put in the step event. The create event is only executed once upon creation of the object in the room, before any of the other events.
 
Top