GML Visual Create Instance

Hi everyone! Id like to create an object via the Create_Instance, but only one.
Because using the Step Event, the object created is more than one.

There is a way I could create just one?

Thanks again! :D
 

Lazzeking

Member
Hi everyone! Id like to create an object via the Create_Instance, but only one.
Because using the Step Event, the object created is more than one.

There is a way I could create just one?

Thanks again! :D
It all depends on when you want this instance to be created.
 

Tony Brice

Member
Hmm, don't know about drag and drop but in simple code form you would set a variable to false in the create event. Not sure if it's going to help putting in code form but:-
Create:
Trigger = false;

Step:
if (Trigger == false) {
if (Health == 2) {
Trigger = true;
Create_instance (whatever);
}
}

So, even if the health stays at 2, the creation of your new instance wont happen more than once even running in the step event.
 
Hmm, don't know about drag and drop but in simple code form you would set a variable to false in the create event. Not sure if it's going to help putting in code form but:-
Create:
Trigger = false;

Step:
if (Trigger == false) {
if (Health == 2) {
Trigger = true;
Create_instance (whatever);
}
}

So, even if the health stays at 2, the creation of your new instance wont happen more than once even running in the step event.
So I just need to use a Script_Instance and copy paste what you wrote?
 

Tony Brice

Member
I don't know as I've never used drag & drop. You'd have to change the create instance line to whatever yours is called, for starters. Additionally one of those lines goes in the create event of wherever the code is running from, not the step event. The code really runs from an actual object itself, not a script.
 

Toque

Member
You can do this with drag and drop. You are creating an instance every step. You want to only create one.


watch this around the 10 minute forward to see how he does it. He limits the creation to ever 3rd step but you can make it only create one.

You need to learn about variables.
 
You can do this with drag and drop. You are creating an instance every step. You want to only create one.


watch this around the 10 minute forward to see how he does it. He limits the creation to ever 3rd step but you can make it only create one.

You need to learn about variables.
The video is not avaible.
 

Toque

Member
Google game maker drag and drop tutorial. It’s the official tuts. 2nd one ten minutes through. Wouldn’t hurt to just watch them. If you can’t figure it out let me know.

It’s really what Brice said but in drag and drop.

It’s an important concept. Step will trigger 60 times a second while condition is true. So will instance create 60 times.

In non GML terms.
...................

Declare variable triggeronce = true


If (health is 2 and triggeronce is true)

Creat instance.
Change triggeronce to false.
............


So when health is 2 it will create one instance. Then it will change triggeronce to false.

The code will be read again but since triggeronce is no longer true it will not create instance again.
 

Slyddar

Member
I've never used drag and drop before, as it seemed limited, but just for fun I went and did what you were looking for. This is how I would do it.

I just set a scenario where when I click the mouse button the players hp drops by 1. Each time this happens it also sets a variable called create_enemy. Then i run a check to see if hp is 2 and the variable create_enemy is true, it creates an enemy at a random x,y. Importantly it then sets create_enemy to false so it doesn't keep running.

You'll find when making games this kind of setup is essential to lots of scenarios, so you'll use something like this many times over.

EDIT: Toque has explained it above and essentially it's the exact same method.
 

Attachments

Toque

Member
I've never used drag and drop before, as it seemed limited, but just for fun I went and did what you were looking for. This is how I would do it.

I just set a scenario where when I click the mouse button the players hp drops by 1. Each time this happens it also sets a variable called create_enemy. Then i run a check to see if hp is 2 and the variable create_enemy is true, it creates an enemy at a random x,y. Importantly it then sets create_enemy to false so it doesn't keep running.

You'll find when making games this kind of setup is essential to lots of scenarios, so you'll use something like this many times over.

EDIT: Toque has explained it above and essentially it's the exact same method.

What did you think of the d and d ?? It’s not as limited as most people believe.
 

Slyddar

Member
What did you think of the d and d ?? It’s not as limited as most people believe.
After a few minutes of playing with it, it was surprisingly capable. In the picture, you can see I created a section that has "if variable" then "if expression", that I would of liked to create as "if variable" and "if expression" instead, but couldn't see how to do that. I assume it's possible, as you can add multiple checks to an "if expression" but just couldn't find how to do that for the "if variable". If that makes sense.
 

Toque

Member
After a few minutes of playing with it, it was surprisingly capable. In the picture, you can see I created a section that has "if variable" then "if expression", that I would of liked to create as "if variable" and "if expression" instead, but couldn't see how to do that. I assume it's possible, as you can add multiple checks to an "if expression" but just couldn't find how to do that for the "if variable". If that makes sense.
I think I know what you mean. You have to move the box it to a certain place (middle right ) and it makes it “and”.

It’s visual so hard to explain as you noticed. Haha.

I came from 4 years with a visual scripting engine. So I started with the d and d. But I couldn’t easily follow and read the GM drag and drop. I found it very powerful but with that over complexity. I actually found the GML easier to read. And quickly realized since only beginners used it, help was sparse.

But the drag and drop is capable.

Your d and d code example will work great. I am on a phone so thanks for doing that.
 
Last edited:

Slyddar

Member
If you look at the "if expression" and "if variable" help,
"if expression" has this:
These actions will now be run if the "if" evaluates to true, while any actions dropped elsewhere will be performed after the "if" block. Note that you can "stack" expressions in the same action by clicking the plus icon beside the action, and giving another expression to check. This will check if all the expressions given return true in one check and only perform the added action code if they do

while "if variable" has this:
These actions will now be run if the "if" evaluates to true, while any actions dropped elsewhere will be performed after the "if" block.

That bold line is missing, indicating there is no way to have an 'and' check with an 'if variable'. I'd be happy to be proven wrong though. I was not able to replicate any middle right drops, as that wasn't an option.
 
Last edited:

Toque

Member
If you look at the "if expression" and "if variable" help,
"if expression" has this:
These actions will now be run if the "if" evaluates to true, while any actions dropped elsewhere will be performed after the "if" block. Note that you can "stack" expressions in the same action by clicking the plus icon beside the action, and giving another expression to check. This will check if all the expressions given return true in one check and only perform the added action code if they do

while "if variable" has this:
These actions will now be run if the "if" evaluates to true, while any actions dropped elsewhere will be performed after the "if" block.

Indicating there is no way to have an 'and' check with an 'if variable'. I'd be happy to be proven wrong though. I was not able to replicate any middle right drops, as that wasn't an option.
No worries. Your example is great.

I looked again and yours is exactly right.
Thanks.
 
Last edited:
Sorry guys but I don't understand how to do so...
my version of GM is older and different from yours and I can't find any of those variabilities options...
 

Toque

Member
Okay. I think Im getting the picture here. Ive never used old versions of GM. The logic is the same.

Here is a tutorial that might help with the old GM. I hope this link works.


PM sent.
 
I've never used drag and drop before, as it seemed limited, but just for fun I went and did what you were looking for. This is how I would do it.

I just set a scenario where when I click the mouse button the players hp drops by 1. Each time this happens it also sets a variable called create_enemy. Then i run a check to see if hp is 2 and the variable create_enemy is true, it creates an enemy at a random x,y. Importantly it then sets create_enemy to false so it doesn't keep running.

You'll find when making games this kind of setup is essential to lots of scenarios, so you'll use something like this many times over.

EDIT: Toque has explained it above and essentially it's the exact same method.
I kinda get what you posted, thanks to Toque's video.
But it's still a bit confusing because of the names appearing in the variabilities.

I'm mean, could you just explain me that using the names of my objects? And leave the variabilities that I need to chage?

The object I want to crate is called: Ascia_Pickup

This is what I've done, and gives me a fatal error...

Screenshot (1).png Screenshot (2).png Screenshot (3).png
 

Attachments

Slyddar

Member
It looks like you almost have it working. The error says that instance_create is an unknown variable. Meaning it doesn't know what that variable is, because as my image shows, even though it's in GMS2, you need to create the variable in the create event first. You also need a condition where you set create_instance to true somewhere else when you want the create to occur.

I've made it again in GMS 1.4 for you. My condition is when I click the mouse on the player hp goes down by 1, and I set instance_create to true then.
 

Attachments

Slyddar

Member
Nothing works... it still says unknown variable create_instance and hp...
If you are using a variable, it's best to first declare the variable. Meaning you have to set it to a value first in the create event. hp and create_instance need to be declared in the create event of the object that is using them.

Like my first image shows, did you add "Set variable create_instance to false" in the create event of the "Fatica" object? You would also need to declare hp as well, if that is producing an error too.
 
Last edited:
S

Swegm

Guest
Create event
executable code
create = 1

Step event
executable code
If create = 1
{
instance_create(x,y,whateverobject)
create = 0
}
 
If you are using a variable, it's best to first declare the variable. Meaning you have to set it to a value first in the create event. hp and create_instance need to be declared in the create event of the object that is using them.

Like my first image shows, did you add "Set variable create_instance to false" in the create event of the "Fatica" object? You would also need to declare hp as well, if that is producing an error too.
I've done it multiple times but it always crashes...

Screenshot (9).png Screenshot (10).png Screenshot (11).png Screenshot (8).png
 

Slyddar

Member
Well that's rather strange. Could you open the actions and screenshot them. These ones:
"Set variable hp to 6"
"if hp is equal to 2"
"Set variable hp to -1"

Also I'm assuming action number 30 is the "if hp is equal to 2" action?
 
Well that's rather strange. Could you open the actions and screenshot them. These ones:
"Set variable hp to 6"
"if hp is equal to 2"
"Set variable hp to -1"

Also I'm assuming action number 30 is the "if hp is equal to 2" action?
Yes, the line 30 is the hp set -2.

Screenshot (12).png Screenshot (13).png Screenshot (14).png
 

Slyddar

Member
I'm totally at a loss as to why it can't find your hp variable. Hopefully someone else can see something I'm missing, but all I can think of is it's bugged out. Gamemaker 1.x and above have the "Clean" button to flush the system, but I don't know if 8 had that option.

Maybe restart the program, create a new project and just set up the one object with the same setup. Also you could get the trial of GMS2 and set it up too. At least then we would confirm it's being set up right, but the program is not doing what it should.
 
Top