GameMaker [SOLVED]The instance create layer coding does not work within the if else statements?

A

Alan Chan

Guest
The instance create layer coding statement does not create any object inside my if else statements?

Here is my code for my object0.Draw Event to draw out my yellow colored sprite0 object.
Code:
draw_sprite(sprite0,1,x,y);
Here is my code for my object0.Left Down , so when I have pressed my left mouse buttons, my mouse.x and my mouse.y will meet up my object0.x and my object0.y.
Code:
mouseX = window_mouse_get_x();
mouseY = window_mouse_get_y()
if (mouseX == object0.x && mouseY == object0.y) {
    instance_create_layer(100,100,"object1layer",object1);
}
Here is my code for my object1.Draw GUI to draw out my testing result if my instance create layer works properly without only my drawing sprite methods.
Code:
draw_set_color(c_white);
draw_set_font(font0);
draw_text(x,y,"test");
At my main point I will need my instance create layer codes to work at inside my if else statement all else is almost impossible to put my instance create layer functions at anywhere else like already. Because, I do not know where else can I put my Draw GUI Event without using my draw_sprite() codes when I should not draw my sprite at all. I should only need to draw my texts afterwards. I already have tried my different ways to fix this problem by putting my instance create layer new objects at inside my if else statement but it just keeps on not working at all.
 
Here is my code for my object0.Left Down , so when I have pressed my left mouse buttons, my mouse.x and my mouse.y will meet up my object0.x and my object0.y.
If you are using the Left Down event on the object0, why are you checking if your mouse x/y is at exactly the same coordinates as the object? The Left Down mouse event only fires when you are clicking on the object itself. If you used the Global Left Down mouse event then you would need to check if your mouse x/y is within the bounding box of object0, but you don't need to do that with the normal Left Down mouse event.
As @Bentley has indicated, it is most likely that your check of the mouse x/y is causing your problems, so why do you not just have this single line in your Left Down mouse event:
Code:
instance_create_layer(100,100,"object1layer",object1);
draw_sprite(x,y,sprite0,1)
What are you trying to help with here? Your syntax for the draw_sprite function is completely wrong. The OP had it correct already.
 
F

Falconsoft-Industries

Guest
Sorry I forgot it’s not the same method as previous versions of game maker... :(
 
F

Falconsoft-Industries

Guest
Look even a average coder gets their arguments in the wrong order in functions 15% of the time.
 
A

Alan Chan

Guest
That line looks like it will cause you problems. It would be hard to position the mouse at the exact origin of an instance of object0. Are you looking to see if the mouse is hovering instead?
Oh wait thanks @Bentley , I do not need my if else statement at my Left Click Event because my left click mouse will automatically detect my x and y axis.

Code:
instance_create_layer(100,100,1,object1);
But, I think if I put my integer 1 layer is better than my string "object1layer" layer.
 
Last edited by a moderator:
But, I think if I put my integer 1 layer is better than my string "object1layer" layer
What? So you are trying to say that the number 1 is going to be the exact I'd of the later that is wanted? You do not know that. If you do not already have the Id of the layer to use then you would want to put the "object1layer" identifier, not some random number that has no guarantee of being the actual layer that is to be used.
 
A

Alan Chan

Guest
What? So you are trying to say that the number 1 is going to be the exact I'd of the later that is wanted? You do not know that. If you do not already have the Id of the layer to use then you would want to put the "object1layer" identifier, not some random number that has no guarantee of being the actual layer that is to be used.
Ok thanks, I think I have figure it out on how to do my string "text_layer" as well. It should looks like this code instead. But, my integer layer type can still work as well. I also have followed up with this YouTube tutorial video to learn how to make my string instance layer type as well.

Also, you will need to create another layers at inside your own Room Editor windows.
Code:
instance_activate_layer("Instances_Text");

instance_create_layer(x,y,"Instances_Text",o_Text);
 
F

Falconsoft-Industries

Guest
For me I just use instance_create_depth(object,x,y,depth)
I know the name of the function and I am sorry if I got the arguments object, x, y, depth, in the wrong order, please forgive me, correct me, but I am quite sure I got it correct I even did use it that way in my game.
 
For me I just use instance_create_depth(object,x,y,depth)
I know the name of the function and I am sorry if I got the arguments object, x, y, depth, in the wrong order, please forgive me, correct me, but I am quite sure I got it correct I even did use it that way in my game.
Sorry to be the one to tell you (as it always seems to be me at the moment ;) ), but nope: instance_create_depth(x, y, depth, object);
Anyway, using the instance_create_depth is a good alternative if you do not want to put the instance on a specific layer and just allow GMS to create a managed layer for you.
 

Smiechu

Member
For me I just use instance_create_depth(object,x,y,depth)
I know the name of the function and I am sorry if I got the arguments object, x, y, depth, in the wrong order, please forgive me, correct me, but I am quite sure I got it correct I even did use it that way in my game.
Is it really such a big fuzz to check it in the manual, before you post it? Or simply type it in the IDE so you can see the hint in the footer???
 
F

Falconsoft-Industries

Guest
Is it really such a big fuzz to check it in the manual, before you post it? Or simply type it in the IDE so you can see the hint in the footer???
Look the reason I cannot do that because I am only capable of accessing the forums on my iPad and the manual is in the actual software on my computer in which I cannot access the yoyogames forums on even when I enter my login details in correctly.
 
Look the reason I cannot do that because I am only capable of accessing the forums on my iPad and the manual is in the actual software on my computer in which I cannot access the yoyogames forums on even when I enter my login details in correctly.
As @Smiechu says, the docs are online - they always have been even back in GMS1.x. I always check the online docs when I am answering questions on the forum (no matter what computer or device I am on) so that I guarantee that I am giving the correct syntax and examples to people. I also find it easy to have the online docs open even when I'm using the IDE so that I can have the docs on a different monitor to the one that I am coding on and don't have to switch between the Help tab and my Workspace when I'm checking things.
 
Top